ABXZone Computer  Forums



Reply
 
Thread Tools Display Modes
Old 07-04-2008, 12:06 PM   #1
johnnyutah
Registered User
 
Join Date: Mar 2006
Posts: 4
Question Deleting directories via DOS using wildcards

Hi

I'm trying to create a batch file to automatically remove directories beginning with "$" in the C:\Windows directory as they're not needed and take up way too much space. I can't seem to get rmdir to do this with wildcards and deltree isn't on XP (my OS). Can someone write out a DOS command line for me which will do this?

Thanks

Dave
(Offline)   Reply With Quote

Advertisement [Remove Advertisement]
Old 07-04-2008, 02:35 PM   #2
PGIV
Registered User
 
PGIV's Avatar
 
Join Date: May 2003
Location: NY
Posts: 257
Re: Deleting directories via DOS using wildcards

Assuming you have administrative rights, just open Windows Explorer, highlight all the folders beginning with "$" and hit delete. They will be deleted.
__________________
ASUS P6T Deluxe V2, BIOS 0302 || Corsair Dominator 3GB TR3XG1600C8D || Intel Core i7 EE 965 || 2X WD 300 GB VelociRaptor || PCP&C PPCT860 860W PSU || eVGA GeForce GTX 285 SSC, 1GB GDDR3, 182.50 Driver || Lite-On LH-20A1S-12 SATA CD/DVD-RW Drive || Sony DDU1615, 16/48 DVD-ROM Drive || ProCase Full Tower || Dell 2707WFP 27" Monitor @ 1920x1200 || Cambridge SoundWorks 'MicroWorks' Speakers || Windows XP Pro/32 bit/SP3
(Offline)   Reply With Quote
Old 07-04-2008, 04:06 PM   #3
Logan_abx
Registered User
 
Logan_abx's Avatar
 
Join Date: Jan 2003
Location: Blue Ridge Mountains, VA
Posts: 384
Re: Deleting directories via DOS using wildcards

Try the following command:

for /d %a in ($*) do rmdir /s /q %a

This will remove any folders (and subfolders) in the current directory that start with a $. The for command is useful for things like this.

Oh yes -- and you can change this to point to the appropriate path, or do a cd at the beginning of the batch file. Either will work.

Logan
(Offline)   Reply With Quote
Old 07-05-2008, 05:02 AM   #4
johnnyutah
Registered User
 
Join Date: Mar 2006
Posts: 4
Re: Deleting directories via DOS using wildcards

Thanks Logan, that works if I type it in to the command prompt but doesn't from a batch file! It keeps saying "a was unexpected at this time", any ideas???

This is the batch file code I'm using:

c:
cd\windows
for /d %a in ($*) do rmdir /s /q %a
(Offline)   Reply With Quote
Old 07-05-2008, 10:55 AM   #5
Logan_abx
Registered User
 
Logan_abx's Avatar
 
Join Date: Jan 2003
Location: Blue Ridge Mountains, VA
Posts: 384
Re: Deleting directories via DOS using wildcards

Yeah, sorry about that. From a batch file, you have to double up the percent signs. So, in a batch file, the line would be:

for /d %%a in ($*) do rmdir /s /q %%a

Two % signs in front of each a. That's just one of those flaky things about the command prompt versus batch engine in Windows.

Logan
(Offline)   Reply With Quote
Old 07-05-2008, 03:14 PM   #6
johnnyutah
Registered User
 
Join Date: Mar 2006
Posts: 4
Re: Deleting directories via DOS using wildcards

Weird, but it works now! Thank you so much, I was tearing my hair out trying to figure this out, you're a genius!
(Offline)   Reply With Quote
Old 07-05-2008, 08:58 PM   #7
INVALiD
Registered User
 
Join Date: Jun 2008
Posts: 65
Talking Re: Deleting directories via DOS using wildcards

You can modify something like this to fit your own needs...

Quote:
@echo off
cls
echo Fred Langa's CleanALL_9x.Bat,
echo an improved Win9x hard-disk cleanup tool.
echo ---------------------------------------------------------
echo Copyright (c) 2002 Langa Consulting
echo LangaList Home Page
echo ---------------------------------------------------------
echo Use Notepad to view file contents before running!
echo Only you can determine if the file contents and
echo structure are OK to run on *your specific* setup.
echo Info/Documentation/Etc: LangaList Home Page
echo -----------
:: This file is offered as-is and without warranty of any kind.
:: This file may redistributed as long as all header information
:: is retained in the final file.
:: DO NOT PROCEED until and unless you have read the precaution/usage
:: info and checked for newer versions at LangaList Home Page
echo This batch file aggressively cleans up all Temp files, compacts your
echo Registry and Cookies Index, empties the Temporary Internet File (TIF) area,
echo compacts your Icon Cache (by deletion) and then runs a disk-check utility in
echo order to verify that your hard drive is healthy after the cleanup operation.
echo .
echo Note 1: This file MUST be run from pure DOS, not from a DOS window. Note 2:
echo This file uses the standard DELTREE command usually found in Windows\Command.
echo Note 3: This file uses DOS environment variables to locate your Windows
echo and other directories. *Read this file* in Notepad or Edit to ensure
echo it will operate as intended.
:: (If you need help understanding DOS environment variables, READ THE
:: DOCUMENTATION LINKS on LangaList Home Page, and
:: especially see LangaList 2000-09-18 )
:: Please also note the COMMON SENSE PRECAUTIONS and legal information here:
:: OpenDNS . The information on that page is included
:: in this file by reference; and your use of this file indicates your acceptance
:: of responsibility for the use of this file.
echo ---------------------------------------------------------
echo If you haven't followed the instructions above, hit ctrl-c to abort; otherwise
pause
cls
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: check that standard environment variables are in use and if not, abort
if %winbootdir% !==! goto noenv
if %temp% !==! goto noenv
if %tmp% !==! goto noenv
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: if the standard smartdrv disk cache is available, use it to speed things up
:: NOTE: Some systems actually work better WITHOUT smartdrv;
:: if you encounter trouble, place two colons "::" in front of the next line.
if exist %winbootdir%\smartdrv.exe %winbootdir%\smartdrv.exe 2048 16
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Next line catches missing/nonstandard deltree directory
if not exist %winbootdir%\command\deltree.exe goto nodeltree
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The next lines wipe out the temp directories in standard locations
deltree /y %winbootdir%\temp\
deltree /y %winbootdir%\tmp\
deltree /y c:\tmp\
deltree /y c:\temp\
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The next lines wipe out the temp directories in nonstandard locations
:: as long as they are aliased in the environmental variables
:: (may repeat actions of previous deltree operations, but no harm is done)
deltree /y %temp%\
deltree /y %tmp%\
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Next line kills garbage files that Office leaves behind
del %winbootdir%\ff*.tmp
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Next line erases the icon cache, saving some resources on restart
if exist %winbootdir%\ShellI~1\ deltree /y %winbootdir%\ShellI~1
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Next line catches missing/nonstandard cookies directory
if not exist %winbootdir%\cookies\*.* goto nocookie
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Next line deletes index.dat in the normal cookies directory
deltree /y %winbootdir%\cookies\index.dat
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Next line checks for, processes standard TIF
if exist %winbootdir%\tempor~1\*.* goto cleantif1
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If no standard TIF, next line checks for the alternate TIF
:: and if 2nd TIF missing, then no TIF has been found; abort
if not exist %winbootdir%\locals~1\tempor~1\*.* goto notif
:: But if 2nd TIF exists, process it
goto cleantif2
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: this line should never run, but is here for completeness
goto end
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:noenv
:: noenv runs if env variables aren't in use
cls
echo Error!
echo There's a problem with one or more of your environment variables.
echo Batch process aborted. No files deleted.
echo Please edit this file manually to insert the correct path
echo to the referenced directories.
pause
goto end
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:nodeltree
:: nodeltree runs if deltree can't be located
cls
echo Error! %winbootdir%\command\deltree.exe not found. No files deleted.
echo Please edit this file manually to insert the correct path
echo to your copy of Deltree.exe.
pause
goto end
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:nocookie
:: nocookie runs if the cookies directory can't be located
cls
echo Error! %winbootdir%\cookies\ not found. No cookie or TIF files deleted.
echo Please edit this file manually to insert the correct path
echo to your Cookie directory.
pause
goto end
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:notif
:: notif runs if the TIF can't be located in either standard location
cls
echo Error! Cannot locate TIF! No TIF files deleted.
echo Please edit this file manually to insert the correct path
echo to your TIF directory.
pause
goto end
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:cleantif1
:: cleantif1 deletes the TIF if in the standard location
if exist %winbootdir%\tempor~1\*.* deltree /y %winbootdir%\tempor~1\
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:cleantif2
:: cleantif2 deletes the TIF if in the usual alternate location
if exist %winbootdir%\locals~1\tempor~1\*.* deltree /y %winbootdir%\locals~1\tempor~1\
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: if scanreg is available, use it to optimize the registry;
:: if you have trouble with this command, see
:: LangaList 2000-10-05
if exist %winbootdir%\command\scanreg.exe %winbootdir%\command\scanreg.exe /opt
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: edit this section to invoke the drive-check utility of your choice
:: by placing double colons "::" in front of any lines you DON'T
:: want to run, and removing the colons from any line you DO want to run.
:: By default, Windows' own Scandisk is enabled as follows
scandisk /all /autofix /nosummary
:: if you prefer Norton Disk Doctor, and have it installed,
:: disable the Scandisk line, above, and remove the colons
:: in front of the following line
:: ndd c: /q
:: you also may edit the Norton command any way you wish, or
:: add commands for any other disk checker you prefer
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:end
echo Done. Please reboot now.
exit

I'd be carefull though
(Offline)   Reply With Quote
Old 07-08-2008, 05:40 AM   #8
johnnyutah
Registered User
 
Join Date: Mar 2006
Posts: 4
Re: Deleting directories via DOS using wildcards

Ha ha, yeah I will be careful, I did get one of the lines wrong in my batch file and it started deleting all files in the Windows directory! Managed to stop it in time tho, just had to rebuild the fonts folder. Deltree isn't available in XP, but will have a look at this and modify, definitely of interest
(Offline)   Reply With Quote
Old 07-08-2008, 06:07 PM   #9
INVALiD
Registered User
 
Join Date: Jun 2008
Posts: 65
Re: Deleting directories via DOS using wildcards

This one is for XP/2000...


Quote:
@echo off
cls
echo Fred Langa's CleanXP Script For WinME/2K/XP
echo ---------------------------------------------------------
echo Copyright (c) 2002 Langa Consulting
echo LangaList Home Page
echo ---------------------------------------------------------
echo Use Notepad to view this script's contents before running!
echo Only you can determine if the file contents and
echo structure are OK to run on *your specific* setup.
echo Info/Documentation/Etc:
echo LangaList Std Edition 2002-04-04
echo -----------
:: This file is offered as-is and without warranty of any kind.
::
:: Please note that this is NOT a finished, ready-to-run tool, but is
:: a kind of template you can use to *create* a custom tool thatís specific to
:: your own particular setup and needs. PLEASE follow the instructions in the
:: link above and inside the rest of this file to ensure that the file
:: contents and structure are OK to run on *your specific* setup.
::
:: Because I don't know your system or setup or needs, I regret that I cannot
:: offer one-on-one advice on modifying the script for your particular system.
:: But you can find all you need via the info above. Or, if youíre new to batch files,
:: check out The Explorer: Save Your Butt With DOS: Pulling It All Together -- Fred Langa -- InformationWeek .
:: Combined, those links either directly contain everything you need to know about
:: working with this batch file, or have pointers to other sites that will tell you
:: all you need to know.
::
:: Legal Info: Your use of this file constitutes your acknowledgement and acceptance of the
:: disclaimers at legal, which are incorporated
:: into this file by reference.
::
:: This file may be redistributed as long as all header/footer information
:: is retained in the final file, and as long as all user modifications are noted.
::
::
echo This script silently deletes all files--- including read-only files! ---
echo from the designated directories and subdirectories.
echo ---------------------------------------------------------
echo DO NOT PROCEED until and unless you have read the precaution/usage
echo info inside this file and at the site above.
echo ---------------------------------------------------------
echo Hit ctrl-c to abort this script; or, if you have fully examined this file and
echo you know it's OK to run your system, then
pause
:: for automatic operation, delete the "pause" above
cls
:: cls line clears the screen
::
::
:: next lines switch to C: drive, change to first folder where you want to delete files
c:
cd "C:\Documents and Settings\[username]\Local Settings\Temp"
:: edit the line above with the correct path and name of the first directory/folder you want to clean out
::
::
:: XP/2k ONLY:
:: if you're using WinXP/2K, REMOVE the two colons from the front of the "del /p /s /f *.*" line below
:: del /p /s /f *.*
:: After you run CleanXP and are sure that you're deleting the correct files, you can change the /p to /q for faster, no-prompt deletions
::
::
::
:: WinME ONLY:
:: if you're using WinME, REMOVE the two colons from the front of the "deltree *.*" line below
:: deltree *.*
:: After you run CleanXP and are sure that you're deleting the correct files, add a "/y" to the line above, thus: "deltree /y *.*" (minus the quotes) for faster, no-prompt deletions
::
::
:: ALL VERSIONS--- now change to next folder where you want to delete files
cd "C:\Documents and Settings\[username]\Local Settings\Temporary Internet Files"
:: edit the line above with the correct path and name of the next directory/folder you want to clean out
::
::
::
:: XP/2k ONLY:
:: if you're using WinXP/2K, REMOVE the two colons from the front of the "del /p /s /f *.*" line below
:: del /p /s /f *.*
:: After you run CleanXP and are sure that you're deleting the correct files, you can change the /p to /q for faster, no-prompt deletions
::
::
::
:: WinME ONLY:
:: if you're using WinME, REMOVE the two colons from the front of the "deltree *.*" line below
:: deltree *.*
:: After you run CleanXP and are sure that you're deleting the correct files, add a "/y" to the line above, thus: "deltree /y *.*" (minus the quotes) for faster, no-prompt deletions
::
::
::
:: ALL VERSIONS---
:: For each additional folder/directory you wish to clean out, repeat the above pattern: Add a CD "FULL PATH TO FOLDER WITH FILES TO DELETE" followed by either the DEL or DELTREE command (as above) according to which operating system you're running.
:: Of course, you replace "FULL PATH TO FOLDER WITH FILES TO DELETE" with the actual path and name of a folder whose contents you want to delete
:: There is no limit to the number of folders/directories you can process this way.
::
::
::
:: ALL VERSIONS---
cleanmgr /sagerun:99
:: The above line assumes you've previously run a "cleanmgr /sageset:99" command. See full instructions.
::
exit
(Offline)   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com

© 2006 - 2014 ABXZone Forums | About ABX Zone Forums | Advertisers | Investors | Legal | A member of the Crowdgather Forum Community