How in Perl, I delete a dir and all it contents, no matter if it has dirs or files inside, i want to del everything!
Apr 6, 2000, 7:54 PM
Veteran (17240 posts)
Apr 6, 2000, 7:54 PM
Post #2 of 11
Views: 8063
Define the directory as a variable:
Change this to your absolute path to your directory.
Then add the following codes in your Perl script:
Regards,
------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Code:
$dir = "/ABSOLUTE/PATH/TO/DIR";Change this to your absolute path to your directory.
Then add the following codes in your Perl script:
Code:
delete $dir;Regards,
------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Apr 6, 2000, 9:22 PM
User (429 posts)
Apr 6, 2000, 9:22 PM
Post #4 of 11
Views: 8040
rmdir() will also return an error - "Deletes the directory specified by FILENAME if that directory is empty". ( http://www.perl.com/.../perlfunc/rmdir.html )
Why not just use system() or exec() to send the "rm -R" command?
Alternatively, use unlink() to remove the files, and then use rmdir() to remove the directory. Seems a waste of resources though, since you'll have to check for the filenames first.
Course, whatever you do, you'll need to ensure you have the permissions to do it.
adam
Why not just use system() or exec() to send the "rm -R" command?
Alternatively, use unlink() to remove the files, and then use rmdir() to remove the directory. Seems a waste of resources though, since you'll have to check for the filenames first.
Course, whatever you do, you'll need to ensure you have the permissions to do it.
adam
Apr 7, 2000, 1:12 AM
Veteran (1311 posts)
Apr 7, 2000, 1:12 AM
Post #6 of 11
Views: 8067
look at http://www.perl.com/pub/doc/manual/html/pod/perlfunc/unlink.html
and also check the rmdir() link
------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell
and also check the rmdir() link
------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell
Apr 8, 2000, 8:54 PM
Veteran (1509 posts)
Apr 8, 2000, 8:54 PM
Post #10 of 11
Views: 8076
Quote:
Propably you dont have File::Path module installed!!That's a good point. Could be, but that should be part of the standard perl installtion.
If you have telnet access, from the command line type:
perl -e 'use File::Path'
If nothing happens, then it is installed. If you receive an error, then there is your culprit.
--mark