Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to use deltree

Status
Not open for further replies.

JLSigman

Programmer
Sep 20, 2001
261
US
Here's the thing: Our tape drives have died a rather horrible death, and I've written a little batchfile using xcopy to backup the most important things every day onto a 120GB drive.

What I'd like to have the batch file do, since it won't run if it doesn't see enough space on the hard drive, is delete everything in the directories I have it saving to before it runs.

The DEL command will take 5 years, since there's several thousand folders, and Windows 2000 CMD.exe doesn't seem to recognize DELTREE. HELP! Thanks,
Jennifer Sigman
Code-borrower extraordinaire
"They call us public servants for a reason..."
 
Rmdir (Rd)
Removes (deletes) a directory.

rmdir [drive:]path [/s] [/q]

rd [drive:]path [/s] [/q]

Parameters

[drive:]path

Specifies the location and name of the directory you want to delete.

/s

Removes the specified directory and all subdirectories including any files. Used to remove a tree.

/q

Runs rmdir in quiet mode. Deletes directories without confirmation.

 
OK... but I don't know all the names of all the directories. Is there a way to use wildcards? Jennifer Sigman
Code-borrower extraordinaire
"They call us public servants for a reason..."
 
I need a command that works on Windows 2000, since I want the batch file to run on a Windows 2000 machines. Is there something that will clear out a directory in Windows 2000 that can be accessed by a batch file, or can be run in the Scheduled Tasks right before the batch file runs? Jennifer Sigman
Code-borrower extraordinaire
"They call us public servants for a reason..."
 
I apologize for overlooking that this was for Win2K machines. Especially if it's on NTFS partitions, the 'RD' command is going to be your best substitute when used with the /s switch.

/s will remove all subdirectories and files including the parent direcotry that you specified. That should be all you need...

~cdogg
 
JLSigman,

rmdir /s c:\dell

...will delete the folder dell, and everything inside of it.

RD or rmdir (same command) does not allow wildcards. If you know the directories where it is saving to on a drive, and you dont want to delete that directory as well - here's a sneaky little aid to doing just that:

D:\Backup
contains 50 folders and subfolders, but you want them all deleted before running the batch again...but want to keep the D:\Backup folder..

Here is what to do:
create a batch file called "deltree.bat"
copy/paste this text in it

@echo off
pushd %1
del /q *.*
for /f "Tokens=*" %%i in ('dir /B') do rd /s /q "%%i"
popd

Then - you can type:
deltree c:\dell

that will delete all files and folders underneath the c:\dell folder WITHOUT deleting C:\dell itself.

Thats about as powerful as i know how to make that command. There might be a way to add wildcard support, but i dont know how.

Hope that helps. pbxman
Systems Administrator

Please let Tek-Tips members know their posts were helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top