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/Windows/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