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
Dir --- Dir1 Dir2 Dir3 CDDir4 ADir5 ..............so on so fort


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.

Quote Reply
Re: [zerocool] archiving the individual directory In reply to

This is fully untested, but should hopefully work :)

#!/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";


Andy (mod)
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!