Link to home
Start Free TrialLog in
Avatar of Marketing_Insists
Marketing_Insists

asked on

file system saftey: unlink vs rmtree vs system calls for directory removal

I keep hearing that I shouldn't use the unlink() command to remove directories because it could damage the file system and should use rmdir() instead.  

But rmdir only removes empty directories so a system call is sometimes easiest to remove directories with files still in them. (and I like to avoid system calls)

What I don't know is how safe is:
  use File::Path;
  rmtree(folder);

The use File::Path module seems to make use of both unlink and rmdir, but looks looks safe, but just want to ping you guys here first to see your experience .
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marketing_Insists
Marketing_Insists

ASKER

Thanks, both helpful