0

I'm running a batch file to delete the contents (and sub-folders) of a temp directory based on the subfolder names existing in deletedirs.txt

FOR /F %%i IN (C:\deletedirs.txt) DO del "C:\temppurge\*" rmdir /s /q "C:\temppurge\"%%i

Deletes the contents of the sub-folders in the temppurge directory but leaves the sub-folders themselves in tact. What am I missing?

aschipfl
  • 33,626
  • 12
  • 54
  • 99
MBoucher
  • 19
  • 2
  • Not the solution, but: you must place an `&` in between two concatenated commands as you have: `del ... & rmdir ...` – aschipfl Sep 21 '17 at 15:32
  • Duplicate of https://stackoverflow.com/questions/6836566/. See my answer there. – Bill_Stewart Sep 21 '17 at 15:34
  • 1
    Possible duplicate of [Batch file. Delete all files and folders in a directory](https://stackoverflow.com/questions/6836566/batch-file-delete-all-files-and-folders-in-a-directory) – Bill_Stewart Sep 21 '17 at 15:39

1 Answers1

0

Use this batch file (shell script).

@echo off
setlocal enableextensions
if {%1}=={} goto :HELP
if {%1}=={/?} goto :HELP
goto :START

:HELP
echo Usage: %~n0 directory-name
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
Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62