- unless (-d $srcdir && -d $destdir ) {die "Error: $!";} + for($srcdir,$destdir) { ! -d $_ and die "Directory '$_' - $!\n" } #### - chdir $srcdir; - opendir(INDIR,$srcdir) || die "Can't open directory: $!"; + chdir $srcdir or die "Can't chdir to '$srcdir': $!\n"; + open my $indir, '.' or die "Can't read '.' in $srcdir: $!\n"; #### unless (-d || $_ eq "." || $_ eq "..") { # . and .. are always -d #### my @files = grep { -f } readdir $indir; #### `tar -cz $_ -f $_.tar.gz`; `mv *.gz $destdir`; #### chdir $srcdir or die "Can't chdir to '$srcdir': $!\n"; open my $indir, '.' or die "Can't read '.' in $srcdir: $!\n"; (my $tarfile = $srcdir) =~ s|.*/||; $tarfile = "$destdir/$tarfile-" . time . '.tar'; my @files = grep { -f and -M <= 1 } readdir $indir; # packing all files at once doesn't work with large directories # (limit of command line length) while(my $file = shift @files) { system ('tar', 'uf', $tarfile, $file) and die "Can't pack '$file' into '$tarfile' (exitcode $?)\n"; } system ('gzip', $tarfile) and die "Couldn't gzip $tarfile (exitcode $?)\n";