Skip to content

Instantly share code, notes, and snippets.

@wizardishungry
Created November 4, 2010 21:56
Show Gist options
  • Save wizardishungry/663282 to your computer and use it in GitHub Desktop.
Save wizardishungry/663282 to your computer and use it in GitHub Desktop.
Script to clean up my download directory. Move all {mp3,m4a} and subdirs with said filenames to a datestamped directory and then reveal in the Finder.
#!/usr/bin/perl
use POSIX qw/strftime/;
use File::Find ();
use File::Copy;
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
$DL="$ENV{'HOME'}/Downloads";
$LIBRARY="/Volumes/Tesseract/New Mp3 Dump";
chdir $DL or die "Couldn't chdir $DL $!";
#`open $DL`
$date=strftime('%Y.%m.%d',localtime);
mkdir $date or warn "Couln't create directory $date, $!";
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _ &&
/^.*\.m4a\z/si
||
/^.*\.mp3\z/si
&& push(@files,$name)
# && print("$name\n");
}
@files =(); %targets = {};
File::Find::find({wanted => \&wanted}, '.');
while(@files) {
$_= pop @files;
s/^\.\///;
s/\/.*$//;
$targets{$_}=$_;
}
while (($key, $val) = each(%targets))
{$key==$date or move($key,"$date/$key") or warn "couldn't move $key into $date, $!";}
`open $date`
@wizardishungry
Copy link
Author

So this isn't working with m4a files right now! I created the wanted() function using find2perl. Can anyone see anytihng wrong with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment