Created
November 4, 2010 21:56
-
-
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.
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 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` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So this isn't working with m4a files right now! I created the wanted() function using find2perl. Can anyone see anytihng wrong with it?