in reply to Delete files if they match help!
Maybe I'm misunderstanding... but can't you just try to delete the files returned from the db query — rather than search through and compare with the entire directory listing every time? If the file doesn't exist in the directory, the unlink call will fail, but so what? it isn't going to hurt the computer. Something like this:
while (my $row = $sth->fetchrow_hashref()) { for my $imgfile (map $row->{"image_$_"}, 1..4) { unlink "../../pics/$imgfile"; } }
And if you don't really care which individual files couldn't be unlinked (by checking the function's return value), you could also pass the entire file list directly to a single unlink call...
unlink map "../../pics/".$row->{"image_$_"}, 1..4;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Delete files if they match help!
by Anonymous Monk on Jan 07, 2011 at 04:08 UTC | |
|
Re^2: Delete files if they match help!
by Anonymous Monk on Jan 07, 2011 at 14:43 UTC | |
by Anonyrnous Monk (Hermit) on Jan 07, 2011 at 14:57 UTC |