Recursive directory removing?

M

MM

Hi,

Can anyone give me some hint on how I in a perl script can remove all
directories, subdirectories, and files (recursively) in a specific directory
that I state? Pretty much like the 'rm -fR' system command, except that I do
not want to use the 'system' command. I looked at the 'unlink' function, but
I could not see how this can be used to remove subdirectories as well.

Many thanks in advance,

MM
 
J

Jürgen Exner

MM said:
Can anyone give me some hint on how I in a perl script can remove all
directories, subdirectories, and files (recursively) in a specific
directory that I state?

If you want to do it the hard way:
perldoc File::Find
and do a depth-first pass.

If you want to do it the very hard way
perldoc -f opendir
perldoc -f readdir
perldoc -f -d

If you want to do it the easy way:
perldoc File::path
Pretty much like the 'rm -fR' system command,
except that I do not want to use the 'system' command. I looked at
the 'unlink' function, but I could not see how this can be used to
remove subdirectories as well.

perldoc -f rmdir


jue
 
G

Gary E. Ansok

Can anyone give me some hint on how I in a perl script can remove all
directories, subdirectories, and files (recursively) in a specific directory
that I state? Pretty much like the 'rm -fR' system command, except that I do
not want to use the 'system' command. I looked at the 'unlink' function, but
I could not see how this can be used to remove subdirectories as well.

Check out the rmtree() function in the File::path module (which you
should already have as part of the Perl installation).

perldoc File::path

-- Gary Ansok
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top