0

I am a bit of a novice at scripting.

I saw your "delete contents of a directory" script on a help site which seemed the safest option offered, but cant get it working from within my batch file:

Can you advise please? I don't think I have the directory entry syntax correct.

@echo off
setlocal enableextensions
if {%1}=={} goto :HELP
pause

if {%1}=={/?} goto :HELP

goto :START

:HELP
echo Usage: %~n0 E:\test1\testL2\testL3
echo.
echo Empties the contents of the specified directory,
echo WITHOUT CONFIRMATION. USE EXTREME CAUTION!
goto :DONE

:START
pushd %1 || goto :DONE
rd /q /s . 2> NUL
popd

:DONE
endlocal
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Try and format you question using the <> code tags. Thanks! – ouflak Dec 18 '14 at 18:23
  • Quite bit hazardous, but... Start with `for /R "%~1" %%G in (.\) do @echo %%~dpnxG` to see your full subdirectory structure. Then you could switch to `for /D %%G in ("%~1\*") do @echo %%G` to see first subdirectory level only. And then, after replacing `echo` with `rd /q /s`, you cannot choose but pray :) – JosefZ Dec 20 '14 at 02:04
  • 1
    Possible duplicate of [Deleting Folder Contents but not the folder](http://stackoverflow.com/questions/38767550/deleting-folder-contents-but-not-the-folder) – aschipfl Aug 04 '16 at 14:17

0 Answers0