Brian268 has asked for the wisdom of the Perl Monks concerning the following question:
Hi I'm trying to sort some files and i'm haveing a spot of bother with part of the script.
The first time it is run a new folder is created but gives an error 'F:\temp\Test\Test14.jpg' and 'F:\temp\Test\Test14.jpg' are identical (not copied) at E:\Perl\NewDir.pl line 30
The second time creates another new folder and copies the file
Note $Old = $New for testing only hance the hard coding the actual files are in multiple folders the new folder will be based on the file name
#!/usr/bin/perl use File::Copy; use File::Path qw(make_path remove_tree); my $path = "F:\\temp\\Test" ; my $New = "F:\\temp\\Test\\Test14.jpg"; my $Old =$New; my $nFile = "Test14.jpg"; my $I=1; if (-e $New) { my $PATH = $path . $I; until (! -d $PATH) { $I++; $PATH = $path . $I; print "I'm in a loop $PATH\n"; $New = qq($PATH\\$nFile); } $path = $PATH; print "path is $path $Old $New\n" ; make_path($path); if (-d $path) { copy("$Old", "$New"); } else { print "$path not existl\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: New Folders
by ikegami (Patriarch) on Dec 15, 2011 at 11:01 UTC | |
by Brian268 (Novice) on Dec 15, 2011 at 12:04 UTC | |
|
Re: New Folders
by jethro (Monsignor) on Dec 15, 2011 at 11:10 UTC | |
by Brian268 (Novice) on Dec 15, 2011 at 12:30 UTC | |
by jethro (Monsignor) on Dec 15, 2011 at 13:02 UTC |