Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Private Utilities

by radiantmatrix (Parson)
on Dec 02, 2005 at 20:29 UTC ( [id://513711]=note: print w/replies, xml ) Need Help??


in reply to Private Utilities

I use Windows at work, and use my Desktop as a workspace. However, I often am too lazy to clean my desktop off (which really just involves moving documents into a directory, archives into an 'Apps' directory {they are usually downloads}, and shortcuts off to a 'Shortcuts' directory). So, I let Perl do the heavy lifting for me:

package main; use strict; use warnings; our $VERSION = '0.01'; our $BUILD = 'Oct 24, 2005'; #__modules__ use POSIX qw[_exit]; use Win32::TieRegistry; use File::Spec::Functions ('catdir','catfile'); use File::Copy; main( \@ARGV ); #_____________________________________________________________________ +__ main()_ sub main { # main ( \@argv ) my $argv = shift; $Registry->Delimiter('/'); my $sh_fold = $Registry->{'HKEY_CURRENT_USER/Software/Microsoft/Wi +ndows/CurrentVersion/Explorer/Shell Folders'}; my $desk = $sh_fold->{'Desktop'}; my $docs = $sh_fold->{'Personal'}; chdir $desk; opendir my $DESK, $desk or die ('Opening Desktop: '.$!); my (@doc, @dir, @exe, @lnk); for (readdir $DESK) { next if /^\.{1,2}$/; # skip . and .. if ( -d $_ ) { push @dir, $_ and next } next unless -f $_; # executable and other "non-document" types if ( /\.(?:exe|zip|tgz|tar|gz|com|msi|ini)$/i ) { push @exe, $_; } elsif (/\.lnk$/i) { next if /^CleanDesk/i; push @lnk, $_; } else { push @doc, $_; } } my $newdir = catdir($docs, 'Cleaned'); mkdir $newdir; $|=1; for (@doc) { print $_,' => '; my $new = catfile($newdir,$_); copy($_, $new) or do { warn "Skipping $_: $!"; next; }; print $new,"\n"; unlink($_); } mkdir catdir($newdir,'Apps'); for (@exe) { print $_,' => '; my $new = catfile($newdir,'Apps',$_); copy($_, $new) or do { warn "Skipping $_: $!"; next; }; print $new,"\n"; unlink($_); } for (@dir) { print $_,' => '; system('move',$_,$newdir); print catdir($newdir,$_),"\n"; } mkdir catdir($newdir,'Shortcuts'); for (@lnk) { print $_,' => '; my $new = catfile($newdir,'Shortcuts',$_); copy($_, $new) or do { warn "Skipping $_: $!"; next; }; print $new,"\n"; unlink($_); } _exit(0); } #_____________________________________________________________________ +_____ END_ _exit(250); ## unknown exit code. Should *never* happen; __END__ =head1 cleandesk.pl Cleans Desktop items into the My Documents folder =cut
<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://513711]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found