Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
The stupid question is the question not asked
 
PerlMonks  

File won't dessapear.

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 muppetBoy (Pilgrim) on Jun 01, 2000 at 13: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 ZZamboni (Curate) on Jun 01, 2000 at 13: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 perlcgi (Hermit) on Jun 01, 2000 at 13: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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.