# Batch file to delete folder



## vdub1.8t

I would like to create a batch file to delete a specific folder. The folder is PGP Corporation. When I try to execute del PGP Corportion it is really trying to delete a folder called PGP. It isn't seeing that PGP Corportation is the entire file name because of the space. Do you know what I need? Thanks for your help!


----------



## teddyk

Values with embedded spaces need to be quoted. Also, you can't just use the del or erase command for directories. You need to use the rmdir (remove directory) command.

Like this:

rmdir /s /q "C:\PGP Corporation"


----------



## vdub1.8t

Works great! Thank you!


----------



## teddyk

glad i could help.


----------



## quarryninja

Hi, I'm really sorry for bringing up this post again, but I couldn't find out anywhere how to do it.

I'm trying to erase the content of a spesific folder with a batch file, not the folder, but just everything inside it. I am using:

del /s /q c:\Temp\*

and it works great, the only problem is that it only erases files not subfolders. How can I get it to erase EVERYTHING inside my "c:\Temp" folder? 

Thanks

*UPDATE*: So I figured out a work around to do what I want:

del /s /q c:\Temp\*
rmdir /s /q c:\Temp\
mkdir c:\Temp

But Im sure there must be something simpler...


----------



## AlbertMC2

You don't need the first "del /s /q c:\Temp\*"
as the "rmdir /s /q c:\Temp\" deletes the folder and everything in it


----------



## quarryninja

Thanks Albert, 

But is there a way to delete everything inside that folder without having to delete the folder itself and creating it again?


----------



## AlbertMC2

I don't believe so. (Though I could be corrected). You used to be able to do that with a program called "deltree" but Microsoft removed it from WinXP onwards.


----------



## quarryninja

Hey, so I've done some changes to my batch file. 

I know most of them are unnecessary but I like to see whats going on, so most of them are only for the looks. 8) 

Tell me what you think, what am I missing, what can I add?

BTW, I added the file to the system's starup, so that whenever it boots up I have a fresh Temp folder (this is where I download all my stuff, and put files that I'm only gonna use once).


@echo off
COLOR 0A
echo ..::TEMP ERASE by DDURAND::..
ECHO.
echo Regenerating "C:\Temp\" folder. . . 25%%
echo Deleteing all files in folder...
@echo on
del /s /q c:\Temp\*
@ping 127.0.0.1 -n 2 -w 100 > nul
@ping 127.0.0.1 -n %1% -w 100> nul
CLS

@echo off
echo ..::TEMP ERASE by DDURAND::..
ECHO.
echo Regenerating "C:\Temp\" folder. . . 50%%
echo Creating new folder...
@echo on
rmdir /s /q c:\Temp\
mkdir c:\Temp
@ping 127.0.0.1 -n 2 -w 100 > nul
@ping 127.0.0.1 -n %1% -w 100> nul
CLS

@echo off
echo ..::TEMP ERASE by DDURAND::..
ECHO.
echo Regenerating "C:\Temp\" folder. . . 75%%
echo Regenerating complete!
@echo on
@ping 127.0.0.1 -n 2 -w 100 > nul
@ping 127.0.0.1 -n %1% -w 100> nul
CLS

@echo off
echo ..::TEMP ERASE by DDURAND::..
ECHO.
echo Regenerating "C:\Temp\" folder. . . 100%%
echo Customizing folder...
@echo on
attrib -h -r c:\Temp\desktop.ini 
echo [.ShellClassInfo] >C:\Temp\desktop.ini 
echo IconFile=%SystemRoot%\system32\shell32.dll>>C:\Temp\desktop.ini 
echo IconIndex=20 >>C:\Temp\desktop.ini 
attrib +h +r c:\Temp\desktop.ini 
attrib +r c:\Temp


----------

