Hello all,
I am trying empty a directory with over 4000 files with a script, and do not understand why I can only delete half at a time. I am guessing that the directory handle has a size limitation?? Is there a way to load the contents into a large array or am I going about this all wrong? Please forgive the newbie question. I'm trying to hack this with my copy of the Perl Bookshelf and limited practical experience.
No Idea how it even works in the first place , just see the comments inline
#!/usr/bin/perl #open directory and load contents into hash $dir = "/test/directory"; opendir(@DIR, $dir) or die "cant opendir $dir: $!";
# It should be opendir(DIR, $dir) or die "cant opendir $dir: $!";
# there are better ways of looping thru all files but if you want to do this
while (defined($file = readdir(DIR))) {
if ($file =~ "klee") { #matching a specific file, avoiding . &
# No not this way ...it should be if($file=~/klee/) {
# Again not @DIR but DIR.. and .AppleDouble directory $file2 = $dir . "/" . $file; unlink($file2); print "unlinking $file2...\n"; } } closedir(@DIR);
But why do you want to do it in perl ( why not rm -f $dir/* $dir/.* ) , If you are removing all the 4000 files everytime it might make sense to remove the entire directory and recreate it.
Ram
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>