Gossamer Forum
Home : General : Perl Programming :

archiving the individual directory

Quote Reply
archiving the individual directory
Hi guys can someone help me how can I do a script the will archive all the directory individualy using perl script
Example
Dir --- Dir1 Dir2 Dir3 CDDir4 ADir5 ..............so on so fort

to

DirArchive --Dir1.tgz Dir2.tgz Dir3.tgz CDDir4.tgz ADir5.tgz ..............so on so fort

note that the original Dir is maintained and you don't know all the contents of Dir1.


Thanks.
Quote Reply
Re: [zerocool] archiving the individual directory In reply to
Hi,

This is fully untested, but should hopefully work :)

Code:
#!/usr/local/bin/perl -w

use strict;
my $folder = '/full/path/to/folder';

opendir(DIR, $folder) || die "Cant read $folder. Reason: $!";
while (defined($file = readdir(DIR))) {
next if $file =~ /\./; #skip normal files, as we only want to do folders...
if (chdir($folder)) {
system("tar -cvvf $file ../$file.tar");
print "Compressed $filde into $folder/$file.tar \n";
}
}
closedir(DIR);

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates