Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Removing files with extentions of log and date-time.

by curtisb (Monk)
on Oct 09, 2000 at 00:56 UTC ( [id://35849]=note: print w/replies, xml ) Need Help??


in reply to Removing files with extentions of log and date-time.

Thanks Everyone. Borrowing from what you have suggested, really helped. I now know where I was screwing up at. How can I delete something when I have skipped it first? That was a good question and a wrong way to think. so thank for your help. If you want to see what the rewritten code looks like, here you go.
#!/usr/bin/perl -w $dir = "(directory path)"; print "Starting Delete Process\n\n"; opendir(DIR, "$dir") || die "No $dir: $!"; @files = grep(!/^\./, readdir(DIR)); @files = sort @files; closedir(DIR); foreach (@files) { print $_, "\n"; if (/\.log$/i || /\.\d+\w+\-\d+\wm$/i || /\.txt$/i) { unlink ("$dir/$_") if (-f "$dir/$_") || print "Unable to delete $_: $!"; } }
Basicly, this script will now delete any log file, date-time file, or text file found in a predetermined directory. Thanks once again for your help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://35849]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-20 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found