By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,809 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,809 IT Pros & Developers. It's quick & easy.

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

P: 6

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:
Expand|Select|Wrap|Line Numbers
  1. open(INFILE, '<',  $the_infile) || die $!;  
  2. #read from infile, modify contents
  4. open(OUTFILE, '>', $the_outfile) || die $!;
  5. #print modified contents to outfile
  7. open(ORIG_INFILE, '>', $original_outfile) || die $!;
  8. #copy content from INFILE to ORIG_INFILE
  10. unlink("$the_infile");
  11. #Rename the OUTFILE with the same name as the INFILE
  12. rename($the_outfile, $the_infile);
  14. close (ORIG_INFILE);
  15. close (INFILE);
  16. close (OUTFILE);
I'm not sure if it's legal to rename($the_outfile, $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!
Aug 11 '10 #1
Share this Question
Share on Google+
2 Replies

P: 6
I solved the problem: Windows will not rename or delete files while they are open.
Aug 11 '10 #2

P: n/a
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.
Sep 29 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.