|
|
|
10.4: Use PERL to keep the desktop clean
long ago i wrote an applescript to clean my desktop. once os x came around, i rewrote it in perl. it is easily adaptable for cleaning out other directories, too.
it simply checks for the file type using the unix 'file' command, and if that is not found, it uses the chars after the last dot in the name. then it copies the files into sorted folders in the destination dir. if a file already exists, it is skipped and is reported back to the shell. it could use more work to sort better, but i almost always find the file i want in a couple of clicks.
#!/usr/bin/perl -w
my $input = "/Users/shemp9999/Desktop"; # directory to clean
my $output = "/Users/shemp9999/Deskcrap"; # directory to move files to
my $file;
my $inf;
my @xtmp;
my $xtmp;
my $base;
my $ext;
my $item;
foreach $file (`ls \"$input\"`){
chomp($file);
# set ignore list for aliases, etc...
$in = "$input\/$file"; #input path with filename
$inf = `file \"$in\"`;
chomp($inf);
@item = split (/\:\s+/, $inf);
$base = '';
$ext = '';
if ($file =~ /\./){ ## if there's a dot in the path/name
@xtmp = split(/\./, $file);
$ext = pop (@xtmp);
foreach $xtmp (@xtmp){
if ($base ne '') {$base .= '.' } ## restore dot
$base .= $xtmp;
}
}else{ ## if there's no dot extension
$base = $file;
}
if ($ext ne ''){
$dir = $ext;
}else{
$dir = $item[1];
}
$out = "$output\/$dir"; #input path with filename
$outpath = "$out\/$file";
unless (stat($outpath)){ ## if the file does not exist
unless (stat($out)){ ## if the path does not exist
`mkdir -p \"$out\"`; ## make the path
}
`mv \"$in\" \"$outpath\"`;## move the file
}else{ ## file exists
print "file $outpath exists, skipping\n";
}
}
10.4: Use PERL to keep the desktop clean
Does not work... it moves all the files to destination directory, but does not sort them at all... Resukting error below
######ERROR######## Use of uninitialized value in string ne at sorter.pl line 40.Use of uninitialized value in concatenation (.) or string at sorter.pl line 46. ######ERROR######## |
SearchFrom our Sponsor...What's New:Hints3 new Hints in the last 24 hoursComments last 2 days
Links last 2 weeksNo recent new linksWhat's New in the Forums?The Editor's Corner...Here are some of my (robg) other projects...
Hints by TopicNews from Macworld
|
|
Copyright © 2010 Mac Publishing LLC (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Powered by Geeklog Created this page in 0.03 seconds |
|