Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: A warning about passing mountpoints as arguments to directory recursion programmes

by ambrus (Abbot)
on Apr 30, 2013 at 19:37 UTC ( #1031461=note: print w/ replies, xml ) Need Help??


in reply to A warning about passing mountpoints as arguments to directory recursion programmes

Maybe it's just that I'm tired, but I don't see how this code is supposed to work. I have multiple problems.

Firstly, the recursivelyunlinkfiles function tries to call itself multiple times, but doesn't have an argument that's changed for the inner calls. What's the point of the recursion then?

Secondly, you're calling unlink without an argument so it defaults to unlinking $_, but I don't see where you're setting $_.

Thirdly, you don't filter out . and .. from the files readdir returns. If you actually recursed on the directory tree, this would lead to either a quick infinite loop, or a dangerous code that traversed the entire file system.

PS. if you just want a recursive deletion function, then take a look at File::Path or File::Path::Simple.


Comment on Re: A warning about passing mountpoints as arguments to directory recursion programmes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2014-07-31 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (249 votes), past polls