Created
February 10, 2010 19:59
-
-
Save sheepmaster/300778 to your computer and use it in GitHub Desktop.
cleanup.pl
This file contains hidden or 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::Path; | |
| sub folder($) { | |
| my $file = shift; | |
| my (undef, undef, undef, $day, $mon, $year) = localtime((stat($file))[10]); | |
| $year += 1900; | |
| $mon = sprintf("%02d", $mon+1); | |
| $day = sprintf("%02d", $day); | |
| return "$year/$year-$mon/$year-$mon-$day"; | |
| } | |
| my $dirname = "$ENV{'HOME'}/Downloads"; | |
| my $dir; | |
| opendir($dir, $dirname) or die "Couldn't open '$dirname': $!"; | |
| while (my $file = readdir($dir)) { | |
| next if $file =~ /^\./ or $file =~ /^\d{4}$/ or $file =~ /\.download$/ or (-C "$dirname/$file") < 1; | |
| my $folder = folder("$dirname/$file"); | |
| mkpath("$dirname/$folder") unless -d "$dirname/$folder"; | |
| rename("$dirname/$file", "$dirname/$folder/$file") or die "Couldn't move '$dirname/$file' to '$dirname/$folder': $!"; | |
| # print "moved $file to $folder\n"; | |
| } | |
| closedir($dir); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment