in reply to one user prompt instead of many
You need to accumulate the list first, then ask the user in case there are any entries, and delete them if so.
my @everyfile = ( glob( "C:/input/*.htm" ), glob( "C:/input/*.doc" ), glob( "C:/input/*.pdf" ), ); my @oldfile = grep -M > 3, @everyfile; if( @oldfile ) { print "Delete files older than 3 days? [Y or N] \n"; chomp( $cleanup = <STDIN> ); if( $cleanup =~ /Y/i ) { unlink @oldfile; } else { print "\n <<No files deleted at this time>>\n"; } }
Note that you can pass multiple files to unlink. Don't loop.
Makeshifts last the longest.
|
|---|