Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

File won't dessapear.

by Punto (Scribe)
on Jun 01, 2000 at 17:30 UTC ( [id://15809]=perlquestion: print w/replies, xml ) Need Help??

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

I have a program that writes to a temp. file, and then deletes it. I do this:
unlink ($path) || die "Couldn't unlink $path\n";
($path is the name of the file). The program doesn't die, but after I run it, the file still exists.. Does that make sense?

Thanks..

Replies are listed 'Best First'.
Re: File won't dessapear.
by ZZamboni (Curate) on Jun 01, 2000 at 17:47 UTC
    No, it doesn't. A few things to check:
    • Does $path contain the full path of the file, or the correct relative path wrt the current directory for the program?
    • Do you have permissions to delete it? (if the same program created it, I would guess so, but permissions could always change in the middle)
    • Is that line actually being executed? Try inserting print statements before and after it, to verify that.

    --ZZamboni

RE: File won't dessapear.
by muppetBoy (Pilgrim) on Jun 01, 2000 at 17:45 UTC
    Not sure why the file has not disappeared - could it be a permissions problem?
    Unlink will return the number of files successfully deleted, you could try:
    $cnt = unlink ($path);
    And check $cnt is what you would expect.
    Also, what is your OS, I'm not sure if unlink works on Win32. Although this could well be wrong.
Re: File won't dessapear.
by perlcgi (Hermit) on Jun 01, 2000 at 17:55 UTC
    Just two suggestions:
    1. If on Unix, have you checked the directory permissions - you need write access to the directory as well as to the file. Could you have created the temp file originally as a different user?
    2. Are you sure as ZZ pointed out that $path contain the full path of the file. unlink will only delete directories if run as root.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-18 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found