Created
April 4, 2023 16:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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