1.

Solve : Batch files to delete files and folders?

Answer»

I need a batch file to delete particular folders like
C:\windows\Temp

When i say this, I dont WANT the TEMP folder to be deleted by all the contents of it. I mean all the data inside it including FILES and folders.

Please help.Do a change directory to C:\Windows\Temp
Then USE the remove directory command to remove the directories.
Then use the delete command to remove the files in the TEMP directory.

Code: [Select]rd /s /q c:\windows\temp
md c:\windows\temp
See, it got executed using this code.


For /D %%I in (D:\test\*.*) DO RD /s /q %%I
Del /F /Q /S D:\test\*.*

However I am unable to use this when there is a space between the path like D:\test\pratik MEHTA

In the above path there is a space between the folder name PRATIK and MEHTA. Hence it doesnt execute. Please provide a resolution. Quote from: Pratik_23 on January 18, 2012, 09:20:42 PM

See, it got executed using this code.


For /D %%I in (D:\test\*.*) DO RD /s /q %%I
Del /F /Q /S D:\test\*.*

However I am unable to use this when there is a space between the path like D:\test\pratik mehta

In the above path there is a space between the folder name PRATIK and MEHTA. Hence it doesnt execute. Please provide a resolution.

"Quotes"
Code: [Select]For /D %%I in (D:\test\*.*) DO RD /s /q %%I becomes
Code: [Select]for /d "usebackq" %%I in ("D:\test\*.*") do rd /s /q %%I
Why not use the original code I gave? It seems like a cleaner process than this. Did it run into problems?It didnt run into the problems but as my destination path folder has a space in it like

C:\test\PRATIK MEHTA\abc

now in the above path there is a space between PRATIK & MEHTA hence the code isnt working. It isnt allowing spaces. Kindly help me RESOLVE that.You have to pute "Quotes" around any path or file name with spaces.


Discussion

No Comment Found