Skip to content

Instantly share code, notes, and snippets.

@ThomasRettig
Created March 31, 2023 11:09
Show Gist options
  • Save ThomasRettig/e2931b916ed50cf60e2acc8060a386b6 to your computer and use it in GitHub Desktop.
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
#!/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