Skip to content

Instantly share code, notes, and snippets.

@nikanos
Created October 7, 2018 18:15
Show Gist options
  • Save nikanos/1173eb94d31369426d990c0c13aa38f0 to your computer and use it in GitHub Desktop.
Save nikanos/1173eb94d31369426d990c0c13aa38f0 to your computer and use it in GitHub Desktop.
Clean old files in folder - Windows batch script
@ECHO OFF
SET days=%1
SET folder=C:\_FolderToClean_
IF %days%.==. GOTO NoDaysEntered
FORFILES /P "%folder%" /D -%days% /C "cmd /c DEL /Q @path"
IF ERRORLEVEL 1 GOTO ForFilesError
GOTO End
:NoDaysEntered
ECHO Please enter the number of days
GOTO ReturnError
:ForFilesError
ECHO forfile command retuned an error!!!
GOTO ReturnError
:ReturnError
EXIT /B 1
:End
Exit /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment