Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Moving a reference file.

by dwatson06 (Friar)
on Jul 23, 2002 at 19:30 UTC ( #184543=perlquestion: print w/replies, xml ) Need Help??

dwatson06 has asked for the wisdom of the Perl Monks concerning the following question:

I am referencing a file that I move after it has been referenced by the perl script. For some reason when I call the command rename and move the file, the file still exists at the old location also. I'm assuming that the computer is holding my reference to that file (Even though I closed it.) and will not let me clear it out of the directory.
This file must be cleared out.
Is there another way to assure the file is removed? Will the unlink command override my reference to it?

Replies are listed 'Best First'.
Re: Moving a reference file.
by Ovid (Cardinal) on Jul 23, 2002 at 19:42 UTC

    If you could post your code, that would help. You can also check out File::Copy.

    use File::Copy; move $old_loc, $new_loc or die "Cannot move $old_loc to $new_loc: $!";


    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Operating environment?
by cebrown (Pilgrim) on Jul 23, 2002 at 20:07 UTC
    Could you tell us your operating system and environment (are you calling Perl from a command prompt or from a web server)?
Re: Moving a reference file.
by derby (Abbot) on Jul 24, 2002 at 13:05 UTC
    Yes, please post a snippet and what OS you're on. If you're moving from one filesystem to another, rename may fail. rename is very OS (well filesystem) intrinsic. Are you checking the return value of rename?

    rename "/foo/bar.txt", "/bar/foo.txt" or die "could not rename $!\n";


      Sorry for the delay, I used the unlink command. It appears to be working fine. I had written the script to reference the file, move it, then encrypt it. I changed this, being that I already have the data from the file, I just create the file in the new location and feed it the encrypted data. On success, unlink the file.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://184543]
Approved by virtualsue
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2023-06-06 08:27 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (26 votes). Check out past polls.