Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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?
thanks,
Daniel

Comment on Moving a reference file.
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: $!";

    Cheers,
    Ovid

    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";

    -derby

      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.
      Thanks

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-08-29 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls