If you run the code in the temp dir then you can just leave the name without a path and remove concerns about handling of \\. I am on slowaris here so I can't test now but I think you can use c:/this/file/spec paths in win Perl and perl will handle the conversion for you, may be worth a go. I have also added some verbosity to the test to narrow down the failure. No time to test it here but it should run...
#!/usr/bin/perl -w use strict; use File::Copy; my $new="mytest"; open NEW, ">$new" or die "I can not open file to write: $!\n"; print NEW "this is a test"; close NEW; if (-f "$new") { print "Created $new file just fine\n"; }else{ print "Did not create $new, most odd\n"; exit 1; } copy ("$new", "$new.new") or die "can't make a copy: $!\n"; if (-f "$new.new") { print "Copied $new to $new.new file just fine\n"; }else{ print "Could not copy $new, most odd\n"; exit 1; } unlink $new or die "can not unlink it: $!\n"; if (-f "$new") { print "Failed to delete $new\n"; exit 1; }else{ print "Deletion works too\n"; } rename ("$new.new", "$new") or die "cant move it: $!\n"; if (-f "$new") { print "Renamed $new.new to $new file just fine\n"; }else{ print "Rename failed, most odd\n"; exit 1; } unlink $new or die "can not unlink it at the end: $!\n"; if (-f "$new") { print "Failed delete second $new, that is realy odd\n"; exit 1; }else{ print "Deletion works again\nEverything looks fine\n"; }
Cheers,
R.
In reply to Re^3: Problem Modifying Files
by Random_Walk
in thread Problem Modifying Files
by mikeatrcn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |