Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

i want to copy the some files to a new directory with previous date name. Ex :

28-04-2007 files [Folder name]
And i do have gzip.exe installed. How to invoke it from perl to zip the folder created. i am using windows servers.
  • Comment on How to copy files to a new directory, and invoke gzip from Perl on Win32?
  • Download Code

Replies are listed 'Best First'.
Re: How to copy files to a new directory, and invoke gzip from Perl on Win32?
by Joost (Canon) on Apr 30, 2007 at 11:52 UTC
    Gzip only zips bytestreams. That means that you normally only gzip a single file. On unix, a common method to package directories is to create a tar archive and gzip that.

    Assuming you have tar and gzip installed, the process is the same for unix and windows:

    system("tar c directoryname|gzip >archive.tar.gz") && die "Error archi +ving directory";
    As for copying files, take a look at the standard File::Copy module.

Re: How to copy files to a new directory, and invoke gzip from Perl on Win32?
by jbert (Priest) on Apr 30, 2007 at 14:43 UTC
    You might want to name your folders with a date which sorts nicely too:
    2007-04-28 2007-04-29 2007-04-30 2007-05-01
    Instead of:
    01-05-2007 28-04-2007 29-04-2007 30-04-2007
    and in answer to your question, you can use the system function in perl to run other executables like 'gzip.exe' and take a look at the rename function or the File::Copy module.
Re: How to copy files to a new directory, and invoke gzip from Perl on Win32?
by scorpio17 (Canon) on Apr 30, 2007 at 13:16 UTC
    You might also want to take a look at the Archive::Zip module, available on CPAN.