Log in

View Full Version : Small DOS command question


road doggy dogg
12-19-2003, 08:54 AM
Okay I made a small batch file on my PC that basically just deletes a lot of temporary files and the like. Like temp. internet files, and temp. files that are caused by programs that aren't deleted and the like (Cool Edit Pro does this a lot :o)

In the file I just use basically "deltree /y C:\folder\*.pk" for instance, and that's all fine and dandy

For whatever reason though, it doesn't delete the files in the folder's subfolders.

Like on my PC, the line is "deltree /y c:\Tony\*.pk", but the files I want are scattered around in the c:\Tony\sounds subfolders, and since I'm constantly re-arranging the folders in there, I'll probably forget to add the different folder names to the file, so instead I'd just like it to delete all the .pk files in the subfolders automatically.

Is there a parameter to add to deltree to make it add to the subfolders as well? 'Cause I thought it just did the folder and everything in it already, but none of the files are getting deleted so I dunno :mad:

CREDO
12-19-2003, 08:22 PM
One need only type “deltree /?” to see a parameter list, but the answer to your question is simple. Deltree is designed to delete folders and subfolders recursively and files in those folders and subfolders, hence the name deltree as in branches of folders and subfolders in the form of a tree. You are not using deltree correctly. Deltree is supposed to have a directory as a parameter not a file, or in this matter (*.pk) which is a pattern for files.

All you need to type is “deltree /y c:\folder” and that will delete that folder including all the subdirectories. Or you can simply say “deltree /y c:\folder\.” That’s a fullstop at the end, meaning delete everything in the directory “folder”, including subfolders and files, but not “folder” itself. There is always the command “mkdir” if a directory needs to be created afterwards, but this should not be necessary using the previous method.

The DOS command “del” is for deleting files, again typing “del /?” will give one a list of possible parameters. You will see the switch /s which instructs the command to “delete specified files from all subdirectories”, therefore, using the command “del /f /s c:\folder\*.pk” will delete all the files in directories and subdirectories in the folder “folder”. The /f switch is simply to “force deleting of read-only files”.

Remember using deltree will delete folders and files recursively in a specified folder. Del is designed to delete files.

So in his batch file you can use:

----- Batch File Starts Here ---------
REM The following line deletes all pk files in the directory “folder” and in all subdirectories
del /f /s c:\folder\*.pk
------ Batch File Ends Here ------

road doggy dogg
12-19-2003, 10:05 PM
Well first off, many many thanks for the help :love:


Howeeeeever :$ When I tried that, I got an "Invalid switch - /F" message. Is my version of DOS too old? :o (I got a similar message if I just used the /s)

When I did the del /? in the DOS prompt, the only parameter thing that showed up was /P, to prompt if you wanted to delete the files :-\

CREDO
12-20-2003, 02:01 AM
<font color=6699FF><b>
http://members.iinet.net.au/~gazza13/apps/DEL16.zip

Use this progam like this

Del16 /S C:\folder\*.pk

that should sort you out.</b></font>

road doggy dogg
12-20-2003, 02:12 AM
CREDO have I ever told you that I love you