Unlink/rename works on linux, not working on windows??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zeebo17
    New Member
    • Jun 2010
    • 6

    Unlink/rename works on linux, not working on windows??

    Hi,

    When I run my program on a linux machine it opens, renames, and unlinks the files as expected. However, when I run it on Windows it will not rename or unlink the files. Since it is opening and reading the files correctly, it seems that the problem is not in the difference between the path name styles.

    Here are the relevant parts of the code:
    [CODE=perl]
    open(INFILE, '<', $the_infile) || die $!;
    #read from infile, modify contents

    open(OUTFILE, '>', $the_outfile) || die $!;
    #print modified contents to outfile

    open(ORIG_INFIL E, '>', $original_outfi le) || die $!;
    #copy content from INFILE to ORIG_INFILE

    unlink("$the_in file");
    #Rename the OUTFILE with the same name as the INFILE
    rename($the_out file, $the_infile);

    close (ORIG_INFILE);
    close (INFILE);
    close (OUTFILE);

    [/CODE]

    I'm not sure if it's legal to rename($the_out file, $the_infile) after I've unliked the $the_infile and I also wasn't sure if I had to close (INFILE) after I unlinked it. Even though it works fine on linux, could this possibly cause the problem on windows?

    Any suggestions would be greatly appreciated!
    Thanks!
  • zeebo17
    New Member
    • Jun 2010
    • 6

    #2
    I solved the problem: Windows will not rename or delete files while they are open.

    Comment

    • Mr Cass

      #3
      thanks for posting, this helped solve my problem. now i must repair the hole in the wall from where my head was banging against it.

      Comment

      Working...