I am trying to make a script to delete all files in the current folder that match a certain pattern. I know that I can use if (-x filename) to check for file existence, and I know that I can use regexp to matcha filename against a pattern. What I do not know is how to combine the two together.
Right now I am using the following code to do the task (forgive me for C style code):
opendir(DIRHANDLE, ".") or die "Cannot opendir: $!"; foreach $fname (readdir(DIRHANDLE)) { if ((-f $fname) && (lc($fname) =~ m/se\d{4}ab/)) { unlink $fname; } } closedir(DIRHANDLE);
While the code does the job, I would like to find a shorter way to do it (and learn a bit more Perl as well). I would appreciate anyone pointing me in the right direction.
UPDATE Sorry, should have specified that i'm using the script in Win environment, so can't use shell...
--------------------------------
An idea is not responsible for the people who believe in it...
In reply to Delete files matching pattern by bofh_of_oz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |