Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Delete files if they match help!

by k_manimuthu (Monk)
on Jan 07, 2011 at 03:51 UTC ( #881002=note: print w/ replies, xml ) Need Help??


in reply to Delete files if they match help!

Check the file is exist. if the file exists then process the unlink process

unlink $file_name if (-e $file_name && -f $file_name)


Comment on Re: Delete files if they match help!
Download Code
Re^2: Delete files if they match help!
by afoken (Parson) on Jan 07, 2011 at 14:59 UTC

    TOCTOU, but why? unlink() won't kill your grandma if the file to be delete does not exist (any more). It will just generate an error ("No such file or directory"). It also generates an error ("Is a directory") when you attempt to delete a directory instead of a plain file (unless you are root, have started perl with the -U flag, and your OS supports unlinking a directory). So, unlink(), check $!, TOCTOU problem gone.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (15)
As of 2014-08-27 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (238 votes), past polls