1.

Solve : MS-DOS commands not working in WinXP?

Answer»

I am playing with a batch file that deletes my files in my temp directories each time I log in to Windows. So far, it works ok using the DEL command (del "C:\Documents and Settings\dad\Local Settings\Temp\*.*" /F /S /Q), but this does not work for sub-directories in the temp folder, just files. In my testing, I determined I can use the RD or RMDIR commands (rd /S /Q "C:\Documents and Settings\dad\Local Settings\Temp") and it works great when in a DOS prompt (command prompt WINDOW), but it is not working when put in my batch file nor from the run line. The windows error says it cannot find 'rd'. Windows is right, there is no separate rd command. RD comes within the command.com. My question is:
How do I get the RD command to work in the batch file? or
What other command can i use in the batch file to get the desired results?
deadw82000,

No sure why it wouldn't work.
I created a directory for testing called C:\Test\tmp and added folders and sub folders and files in each folder. Then I run a batch called x.cmd with the content:

@echo off
del "C:\Test\tmp\*.*" /F /S /Q
rd "C:\Test\tmp" /S /Q
pause


And it correctly removed the tmp folder and everything in it. Having extensions enabled I got the following output:

C:\Test>x.cmd
Deleted file - C:\Test\tmp\a.txt
Deleted file - C:\Test\tmp\aa.txt
Deleted file - C:\Test\tmp\au.txt
Deleted file - C:\Test\tmp\Document.txt
Deleted file - C:\Test\tmp\u.txt
Deleted file - C:\Test\tmp\1w2e3.default\Document.txt
Deleted file - C:\Test\tmp\1w2e3.default\u.txt
Deleted file - C:\Test\tmp\1w2e3.default\ua.txt
Deleted file - C:\Test\tmp\1w2e3.default\uu.txt
Deleted file - C:\Test\tmp\1w2e3.default\x.txt
Deleted file - C:\Test\tmp\1w2e3.default\x1.txt
Deleted file - C:\Test\tmp\1wed45.default\a.txt
Deleted file - C:\Test\tmp\1wed45.default\aa.txt
Deleted file - C:\Test\tmp\1wed45.default\au.txt
Deleted file - C:\Test\tmp\1wed45.default\Document.txt
Press any key to continue . . .

If you think the command processor doesn't find the rd command then try starting a new one for the rd command, i.e.:

[highlight]cmd /c[/highlight] rd "C:\Test\tmp" /S /Q

Any luck?That was it. The command processor wasn't finding the RD command. Using the last line you posted, it worked like a charm. Thanks!

So now this simple file that I have in my startup folder has 3 lines that automatically clean up all of my temp folders and temp internet files upon login. One more added line deletes my COOKIES. Too cool.

cmd /c rd "C:\WINDOWS\Temp" /S /Q
cmd /c rd "C:\Documents and Settings\dad\Local Settings\Temp" /S /Q
cmd /c rd "C:\Documents and Settings\dad\Local Settings\Temporary Internet Files" /S /Q
cmd /c rd "C:\Documents and Settings\dad\Cookies" /S /Q




Maybe you can help me with the next step? I have multiple profiles on this system for each member of my family. Instead of having to create 5 separate batch files, modifying the 2nd and 3rd lines to identify the unique fully qualified path to the temp folders, then putting them in each respective startup folder in each profile, I know there has to be a way to make just one batch file that will apply to all. For the first line above pointing to the windows\temp dir, no modifications are needed. But for the 2nd, 3rd and 4th that include the user profile name, is there a variable I can use in place of the 'dad'? Maybe something where windows can identify the profile that is logging in and insert that name in the area in question to point the command to the correct location in each profile? I hope I am explaining that correctly.

If this can be accomplished, this file can be used on any of my (or other peoples) computers with little to no modification. All they would need to do is put it in their startup folder. I could even make a self-extracting executable to extract it to a pre-specified folder (say c:\util) and then add a reg entry to the HKLM...Run folder to it invokes on any startup of windows (I may be getting ahead of myself here, but this part is relatively easy for me).

First thing to solve is to make those 3 lines UNIVERSAL with a variable. Any ideas?

I know this posting area is for DOS, so if I should post this in the Windows area, let me know.

Thanks again!

Howard




Discussion

No Comment Found