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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.