Skip to content

Instantly share code, notes, and snippets.

@bbchriscesar
Created April 4, 2023 16:41
Show Gist options
  • Save bbchriscesar/833c9c269d99131ed2c33268bff1980c to your computer and use it in GitHub Desktop.
Save bbchriscesar/833c9c269d99131ed2c33268bff1980c to your computer and use it in GitHub Desktop.
This Windows batch script will scan a given directory and permanently delete any files or subdirectories found without warning. If no files or subdirectories are found, the script will simply exit without taking any action.
@echo off
set dir_path=C:\Example\Directory
if not exist "%dir_path%" (
echo Directory does not exist.
exit /b
)
echo Scanning directory "%dir_path%"...
for /f "tokens=* delims=" %%a in ('dir /b /s "%dir_path%"') do (
if exist "%%a" (
echo Deleting "%%a"...
rd /s /q "%%a" >nul 2>&1 || del /f /q "%%a" >nul 2>&1
)
)
echo Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment