Small question, hard answer! This depend of the system, the
type of file, if is directory, link, is loked or opened,
etc...
* For files:
your need to know if you have permission (like unix), and
if it's loked, and in some systems if it's opened.
"Don't assume that a single unlink completely gets rid of
the file: some filesystems (like VMS) have versioned
filesystems, and unlink() removes only the most recent one". (from pod)
* For links (if the OS accept):
Are you trying to delete the link or the target of the
link!? If is the target all the check for files need to be
done.
* For directorys:
In almost OS, it need to be clean, without files or sub-directorys inside. In some OS like Windows it can't be opened by another program.
If you really want to make this easy and safe, use a module! The advantage of the module is that it makes all the checks, for each OS, and the code are already tested!
* See this modules:
File::CheckTree (Maybe this is only what you need)
File::Spec (for path)
File::Stat (can be usefull for links)
filestest (Another way to test permissions)
The good thing is that this modules comes with the standart release! :-P
Take a look at
"perlport - Writing portable Perl", specially in the item "Files and Filesystems", but you should read every thing, lot of things that we have to know are there!
"The creativity is the expression of the liberty".