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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.