Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: Private Utilities by radiantmatrix
in thread Private Utilities by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found