Created
March 31, 2023 11:09
-
-
Save ThomasRettig/e2931b916ed50cf60e2acc8060a386b6 to your computer and use it in GitHub Desktop.
Deletes files in a specified directory (and its subdirectories) that don't have a file extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use File::Find; | |
my $dir = "/path/to/directory"; # specify directory path here | |
find(\&process_file, $dir); | |
sub process_file { | |
if (-f && !/\.[^.]+$/) { | |
print "Do you want to delete file: $File::Find::name? [y/n] "; | |
my $response = <STDIN>; | |
chomp $response; | |
if ($response =~ /^[yY]/) { | |
print "Deleting file: $File::Find::name\n"; | |
unlink $_; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment