Microsoft Certified Professional Magazine OnlineThursday: December 4, 2008 - 08:59 PST
Microsoft Certified Professional Magazine Online About Us | Subscribe to Redmond | Tech Library | Sponsored Webcasts | Get Newsletters
MANAGING THE WINDOWS®  NETWORK MCPmag.com via RSS
-- advertisement --

Microsoft Unified Communications Virtual Conference and Trade Show: Wednesday, May 21
Watch Free Webcast: Optimize Your VMware Infrastructure with the New Releases from the Symantec Backup Exec Family
FREE MAGAZINE SUBSCRIPTION
Get a Free Subscribtion to Redmond magazine in Print or Digital Format!


... Home ... Columns You are reading ... Windows Tip Sheet ... Article

COLUMN
Windows Tip Sheet

Clean Up Your Room
Two-steps to sanity ... er ... a cleaner server.

by Jeffery Hicks
send e-mail link to article SEND  print article PRINT rate the article RATE AND COMMENT get an RSS feed
December 2006

Jeffery  Hicks
How often did your mom tell you to pick up after yourself? It's something you probably tell your users as well. It's a sad fact, but occasionally you need to do some housecleaning. Depending on your applications, you may find all sort of backup and temp files that simply need to be cleaned out. Here's an easy, two-step process.

 

-- advertisement --

 

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the MCPmag.com editors at editor@mcpmag.com; the best questions get answered in this column and garner the questioner with a nifty Redmond T-shirt.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

 

First, we'll use the FOR command to create a text file

FOR /f %x in ("~*.*,*.bak,*.tmp,*.dmp") do @DIR E:\Files\%x /s /b >>deleteme.txt

In parentheses and quotes, add all the file extensions you want to find separated by commas. Change the DIR path accordingly. This command will recurse from this directory and record the full path of every file found in the deleteme.txt file. The command will append to deleteme.txt if it already exists, so delete the file before running the command again or use a different file name.

When the command finishes, review deleteme.txt to make sure there's nothing you want to keep. Edit the file as needed. To delete all the files, simply run:

FOR /f "tokens=*" %x in (deleteme.txt) do @DEL "%x"

In no time at all you've have your server cleaned up and you'll be able to go out and play.

I'll come back to these techniques in another column and exploit them further. end article

Jeffery Hicks, MCSE, MCSA, is a Microsoft PowerShell MVP and scripting guru for SAPIEN Technologies. Jeff is a 16 year IT veteran who has co-authored and written several books, courseware and training videos on administrative scripting and automation. He is the co-author of Advanced VBScript for Microsoft Windows Administrators (Microsoft Press) and Windows PowerShell:TFM (SAPIEN Press). His latest is WSH and VBSCript Core:TFM (SAPIEN Press). You can contact Jeffery about "Clean Up Your Room" at jhicks@sapien.com.
send e-mail link to article SEND  print article PRINT rate the article RATE AND COMMENT get an RSS feed



More Columns

Command Performance December 2008

A Tasty Dish of Worms and Spam December 2008

Lessons in Logic December 2008

Internet Impeded by ISA Server Firewall December 2008

Clustering and Rolling Upgrades (Exam 70-642) December 2008

A Fix for Database Orphans December 2008

The Great Recession? December 2008

Bionic Scheduled Task Reporting December 2008

Backup (Almost) Made Easy December 2008

2009: The Year of Windows 7? December 2008


...read COLUMNS ARCHIVE

Current MCPmag comments for
Clean Up Your Room
There are 7 comments with an average rating of: three stars - good
PAGE 1 of 1
Thursday - 12/7/06: John from Portland says: five stars - excellent
how does one learn what all those characters mean
Thursday - 12/7/06: Mike from South Bend says: three stars - good
I tried this but it always stated File Not Found with the first FOR. The file types in the first list should be seperated by a space, not a comma. Also, if putting this in a BAT or CMD file, you need %%x instead of %x
Thursday - 12/7/06: David Bayer from Nashville says: three stars - good
The syntax on the command in the article is off. Default delimiter using "for /f" is a tab or space, you need the "delims=," parameter if you want a comma-separated list. It also by default only reads the first token, so you also need the "tokens=1-4" parameter if you want more than just the ~*.* files. It would be easier to use for /r l:\ %x in (~*.* *.bak *.tmp *.dmp) do @DIR "%x" /s >>"deleteme.txt" Replace "l:\" with the root folder that you wish to search. I put quotes around %x and deleteme.txt because the way this is written, if there's a space in either file name then the "do" portion will choke.
Thursday - 12/7/06: anatoliy from new york says: three stars - good
CCleaner can do a good job too.
Thursday - 12/7/06: Gantry says: three stars - good
Thanks, David. I had to add the " /b" parameter to to your suggested syntax for it to work, otherwise in the text file it just had a bunch of volume information repeated for every entry. So, this worked for me: For /r |:\ %x in (~*.* *.bak *.tmp *.dmp) do @DIR "%x" /s /b >>"deleteme.txt"
Tuesday - 12/12/06: Ron from Chicago says: two stars - fair
I just get a "More?" prompt. Guess I don't understand how to run this command.
Thursday - 4/26/07: Dean from Springfield, MA says: four stars - very good
This is great and gets me almost everything I need. Is there a way to have the file listed include date and time information, along with the file size. But without volume, directory, and summary information?

Select a Rating for Clean Up Your Room
five stars - excellent excellent
four stars - very good very good
three stars - good good
two stars - fair fair
one star - poor poor
name: (optional)location: (optional)e-mail: (optional)
Comment about Clean Up Your Room
 
TOP


Home | Subscribe/Renew | About Us | Contributors | Tech Library | Tech Library Webcasts | RSS Feeds  RSS Feeds from MCPmag.com
Issue Archive | Blogs | Certification/Careers | Chats | Columns | Now Online | Exam Guide | Events | Features | Forums
MCP Radio | News | Poll | Tech Portals | Press Releases | Reviews | Salary Surveys | Search | Site Map
For more information, e-mail editor@mcpmag.com.
Application Development Trends | Campus Technology | CertCities.com | The Data Warehousing Institute ! E-Gov | EduHound
ENTmag.com | Enterprise Systems | Federal Computer Week | Government Health IT | IT Compliance Institute
MCPmag.com | Recharger | Redmond Developer News | Redmond | Redmond Channel Partner | Redmond Report
TCPmag.com | T.H.E. Journal | TechMentor Conferences | Virtualization Review | Visual Studio Magazine | VSLive!
Copyright 1996-2008 1105 Media, Inc. See our Privacy Policy.
1105 Redmond Media Group
.