in reply to deleting a file in perl
Something like this using File::Find, which IMHO is an overkill for what you need,
since you are just going through one directory, you could consider using opendir, if you want.
NOTE: Deleting a file could be both dangerous and so painful if in error, a wrong file is deleted, hence the need to check the file before deleting.use warnings; use strict; use File::Find qw(find); die "No directory is specified" unless defined $ARGV[0]; my $dir = $ARGV[0]; find( \&unwanted, $dir ); sub unwanted { if (/^\.{1,}/) { return } else { print "Do you want to delete ", $_, $/; chomp( my $ans = <STDIN> ); unlink $_ if $ans =~ /\by\b/; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |