|
Answer» I am trying to create a batch FILE that will delete the contents of any folder (not the folder itself) called "temp" located on my C drive. The temp folders may or may not be directly under the root. For example I would want it to delete the contents of the following folders.
C:\temp\ C:\test\TEMP\ C:\test1\test2\TEMP\
Thank you, ScottThis should work:
Code: [Select]@echo off echo Start Cleaning pause for /R "C:\" %%a in (TEMP\*) do ( echo Found Temp folder: echo %%~dpa pause cd %%~dpa del /Q *.* ) echo Done pause
Thanks for the code but thiere is an issue with it.
I changed the /Q to a /P to check its functionality and found that it WANTS to delete files from my desktop that do not have temp in the path.
Thanks, ScottSorry about that, hold onI believe this should work, sorry about the last script, didn't REALIZE that.
Code: [Select]@echo off echo Start Cleaning pause for /R "C:\" %%a in (*) do ( echo %%~dpa | findstr "TEMP" > temp.tmp for /f "delims=." %%b in (temp.tmp) do ( echo Found Temp folder: echo %%a pause echo %%a pause del /P "%%a" ) del temp.tmp ) pause Hope this helps ,Nick(macdad-)The batch file still doesn't seem to be working. I have modified it slightly to show more info. Below is the output I get. Thanks for your help!
P:\Profile\Desktop>REM @echo off
P:\Profile\Desktop>echo Start Cleaning Start Cleaning
P:\Profile\Desktop>pause Press any key to continue . . .
P:\Profile\Desktop>for /R "C:\" %a in (*) do ( echo %~dpa | findstr "TEMP" 1>temp.tmp for /F "delims=." %b in (temp.tmp) do ( echo Found Temp folder: echo %a pause echo %a pause del %a" /P ) del temp.tmp /P )
P:\Profile\Desktop>( echo C:\ | findstr "TEMP" 1>temp.tmp for /F "delims=." %b in (temp.tmp) do ( echo Found Temp folder: echo C:\140engc2.exe pause echo C:\140engc2.exe pause del C:\140engc2.exe" /P ) del temp.tmp /P ) P:\Profile\Desktop\temp.tmp, Delete (Y/N)?Did you replace the C:\ with the drive letter that you would run this batch on?
C:\ to P:\
|