Friday, February 26, 2010

Automating and housekeeping my computer...

   Just still on a good vibe here from getting all my important information off the desktop and onto the server where backing it up is no longer something either I, or my desktop, have to worry about.  Now I thought I'd share how I automated some of the housekeeping that happens on my computer on a daily basis.
   Some background first.
   My wife and I listen to podcasts quite a bit.  Her on her walk to work, and myself, when I'm out driving around alone (I have a stereo that can play mp3's on SD cards, I don't wear headphones while driving, that would be weird.
   I also have an adorable son, and while we take loads of photos of him for ourselves, friends and family also love to take their own pictures and send them to me, which I like to add to our personal collection for backup and Picasa.
   Finally, I find myself often downloading programmes or files, using them, deleting them, then realizing I want to try them again after reading more, so I like to file them properly and keep them around.
   I tried Lifehacker's Belvedere programme, but it wasn't able to perform multiple functions on the same file, and I also have a personal bias against installing anything that requires, well, installing!
   By first downloading the Microsoft forfiles.exe (available here) to my C:\WINDOWS directory, and working some huge command line voodoo, I was able to achieve all my ambitions directly from the command line.
   First I created the following batch file :


rem Copy podcasts to the podcasts directory.


copy /y "\\NAS\Volume_1\My Documents\*.mp3" "\\NAS\Volume_1\My Documents\My Miscellaneous\My Podcasts\"


rem Move podcasts to the wife as well.


move /y "\\NAS\Volume_1\My Documents\*.mp3" "\\NAS\Volume_1\My Documents\My Miscellaneous\Wife's Podcasts\"


rem Move pictures to My Pictures directory.


move /y "\\NAS\Volume_1\My Documents\*.jpg" "\\NAS\Volume_1\My Documents\My Pictures\"
move /y "\\NAS\Volume_1\My Documents\*.gif" "\\NAS\Volume_1\My Documents\My Pictures\"
move /y "\\NAS\Volume_1\My Documents\*.bmp" "\\NAS\Volume_1\My Documents\My Pictures\"
move /y "\\NAS\Volume_1\My Documents\*.pdf" "\\NAS\Volume_1\My Documents\My Pictures\"


rem Move everything else to My Flotsam directory and delete stuff older than a month.


move /y "\\NAS\Volume_1\My Documents\*.*" "\\NAS\Volume_1\My Documents\My Miscellaneous\My Flotsam\"
PushD "\\NAS\Volume_1\My Documents\My Miscellaneous\My Flotsam" &&("forfiles.exe" /s /m *.* /d -31 /c "cmd /c del @file") & PopD


rem Run CCleaner.


"\\NAS\Volume_1\My Documents\My Miscellaneous\My Essentials\CCleaner\CCleaner.exe" /AUTO


rem Standby Computer.


rundll32 powrprof.dll,SetSuspendState 


  You can sorta see how it all works.  I download EVERYTHING to the root "My Documents" folder (which has such a long UNC because it's actually been moved off the desktop and onto the NAS), and from there, either specifically define where I want it to go, or just sit back and let my computer do the common ones for me.
   MP3's get copied and them moved to both of our directories, because we have such similar tastes in what we want to listen to.  Pictures (and .PDF's) get copied to the My Pictures folder where I can organize them further before letting Picasa work its magic.  Everything else goes to the "My Flotsam" subdirectory, where it can sit for a month before being automatically deleted thanks to the forfiles executable which really should be included with every flavour of Windows!
   Now, all you need to do is head to Start > All Programs > Accessories > System Tools > Scheduled Tasks and create a new task that points to your batch file.  I have decided to let my computer go to standby, as it only takes four seconds to come back, and hopefully saves a bit of hydro and money...  So I have the task scheduled to run whenever the computer has been idle for ten minutes.  The final line of the batch file is the command prompt method for putting your computer into standby (or do they call it sleep nowadays?)
   Anyway, it took me a bunch of ciphering and pilfering from other websites to get this all together and working for me, and I thought others might appreciate it...  Let me know!


No comments:

Post a Comment