in reply to Re: Re: Re: Re: Please help - problem with script on Win2K
in thread Please help - problem with script on Win2K

You need to use the absolute path in both the mkdir call and the rename call. the following two lines will make the the script current working directory (cwd) the directory you specify. You'll also not that I have used forward slashes rather than doubled backslashes. The result is the same, but this is rather more readable I think. This will work for all pathnames within Perl, even on Win32 (and other DOS-like systems as the pod would have it:).

use Cwd 'chdir'; chdir '//10.1.1.5/Weblogiclogs';

Alternatively, simply prepend the directory name to the filename as in

my $createdir = '//10.1.1.5/Weblogiclogs' . strftime( '%y%d%e%H%M%S', +localtime);

As for where the directory you created was created and the files moved to, that will depend what the cwd was at the time. If you had run the script from the command line, it would have been the same as the directory you were in when you ran it? At least under any circumstances I can think of.

As for where the directory/files that you created/moved are - probably the easiest way to find them would be to use the Start->Find...->Files or Folders... option and enter the name of the directory you created.


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Please help - problem with script on Win2K
by Anonymous Monk on Sep 19, 2002 at 01:56 UTC
    Hi There, As per you recomendation, I redid the code. It creates the folder in the location I want with time stamp, but I can not move the logs in the "weblogiclogs" directory into the newly created folder. Am I doing anything wrong? Please help! Thanks again for your help! I'm new to perl but learning from your wisdom! use POSIX; my $createdir = '\\\\10.1.1.5\\Weblogiclogs\\' . strftime( '%y%m%d%H%S', localtime); my $logs = '\\\\10.1.1.5\\Weblogiclogs\\*.log'; { mkdir $createdir or die "Couln't create $createdir because $!($^E)\n"; } sub moveLog { move($logs, $createdir) or die "error moving $logs reason $!($^E)"; }

      The following program should solve your immediate problem. I have tested it as far as I can, but if there are permission problems with your shares etc. you'll need to get someone who supports your systems to solve that.

      If you have further problems with Perl, and from your code its likely you will, could I

      • recommend you invest in a good book.
      • Ask you to please read this before you post any more questions here. Every one of your posts to-date has had to be edited by one of the editors here before it was readable enough for anyone to even attempt to help you. (Clue: Wrap your program code in code tags eg. <code> ---paste your code here---</code>)

      If your serious about learning Perl (rather than just solving your immediate problem), then I highly recommend that you consider going here and becoming a member. It's free and you will find it a lot easier to keep track of your posts and their replies if they don't get mixed up with all the other Anonymous Monk's posts.

      #! perl use warnings; use strict; use POSIX; use File::DosGlob 'glob'; use File::Copy; my $createdir = '\\\\10.1.1.5\\Weblogiclogs\\' . strftime( '%y%m%d%H%S +', localtime); my $logs = '\\\\10.1.1.5\\Weblogiclogs\\*.log'; if( ! -e $createdir ) { mkdir $createdir or die "Couln't create $createdir because $!($^E) +\n"; } my @logs = glob( $logs ); for my $file (@logs) { print "Moving file:$file to $createdir\n"; move( $file, $createdir ) or warn "Couldn't move file:$file becaus +e $! ($^E)\n"; }

      Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!