How do I remove all files and sub-directories from a folder, without removing the folder?

@echo off
if {%1}=={} @echo Syntax: DelTree Folder&goto :EOF
if not exist %1 @echo Syntax: DelTree Folder – Folder %1 does not exist.&goto :EOF
pushd %1
if %ERRORLEVEL% NEQ 0 @echo Syntax: DelTree Folder – Folder %1 does not exist.&goto :EOF
del /q /f “*.*”
for /f “Tokens=*” %%i in (‘dir %1 /B /A /AD’) do rd /s /q “%%i”
popd

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s