in reply to Re: Is there a -e test for directories, like there is for files?
in thread Is there a -e test for directories, like there is for files?
#! /usr/bin/perl use strict; use warnings; use File::Path; use File::Copy; use Cwd; print "Your Input: "; chomp(my $filename = <STDIN>); my $dir = getcwd; my $backupdir = 'backup_files'; my $back = $filename . ".bak"; my $backful = $dir . "/" . $backupdir . "/" . $back; print "\$dir is: $dir\n"; print "\$filename is: $filename\n"; print "\$backupdir is: $backupdir\n"; print "\$back is: $back\n"; print "\$backful is: $backful\n"; unless (-e $backupdir) { mkpath($backupdir); } if (-e $backupdir) { if (-d $backupdir) { opendir (DIR, $backupdir) or die $!; my @files = readdir DIR; print "\@files is: \n"; foreach (@files) { print $_, "\n"; } if (grep {$back} @files) { print "Backup copy of $filename exists!\n"; } else { copy ($filename, $backful); print "Backup copy of the file has been created\n"; } } else { print "\$backupdir exists, but it is not a directory\n"; } }
Any thoughts on where I am going wrong?
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Is there a -e test for directories, like there is for files?
by ikegami (Patriarch) on Feb 08, 2007 at 20:55 UTC | |
by mdunnbass (Monk) on Feb 08, 2007 at 21:15 UTC | |
by johngg (Canon) on Feb 08, 2007 at 23:51 UTC | |
by ikegami (Patriarch) on Feb 08, 2007 at 21:18 UTC | |
|
Re^3: Is there a -e test for directories, like there is for files?
by ikegami (Patriarch) on Feb 08, 2007 at 21:00 UTC | |
by mdunnbass (Monk) on Feb 08, 2007 at 21:06 UTC |