@ECHO Off REM -- Prepare the Command Processor Setlocal Enabledelayedexpansion Title delete_files_folders_fast_robocopy_v3.bat REM Description: Use parameters or drag and drop to fast delete files and folders. REM Uses Robocopy for folders, DEL command for files. Deletions by Robocopy REM displayed, but not for dragged and dropped files using DEL. REM Errorlevel 0 or 2 are normal for Robocopy and can be ignored REM Output by Robocopy not surpressed REM Ref: http://mattpilz.com/fastest-way-to-delete-large-folders-windows/ REM Ref: https://superuser.com/questions/416071/how-to-delete-huge-number-of-files-on-windows REM change to current directory pushd "%~dp0" REM ---------------- set path for RoboCopy if required ---------------------- set path="F:\Utilities\commandlinetools\backup_copy_utilities\robocopy";%path% REM ------------------------------------------------------------------------- REM Remove existing EmptyDir If exist "%~dp0EmptyDir" RMDIR /Q "%~dp0EmptyDir" REM ---------------------------- set colors --------------------------------- REM Uncomment one option below to set REM Yellow on Black REM COLOR 0e REM White on Blue REM Color 1F REM Black on Yellow REM Color e0 REM Blue on Yellow REM Color e1 REM 0=Black,1=Blue,2=Green,3=Aqua,4=Red,5=Purp,6=Yellow,7=White,8=Gray,9=Lt Blue REM A=Lt Green,B=Lt Aqua,C=Lt Red,D=Lt Purp,E=Lt Yellow,F=Bright White REM ---------------------------- end colors ---------------------------------- ECHO Use parameters or drag and drop file^(s^) or folder^(s^) on this script ECHO to fast delete them. Uses Robocopy for folders, DEL for individual files ECHO. ECHO This version displays output from RoboCopy ECHO All files or folders to delete should be in the same directory ECHO. ECHO This script fast deletes files or folders but without an easy way to ECHO recover the contents^^^! ECHO. ECHO. ECHO ------------------------- ECHO. REM Test for empty parameter IF [%1] == [] ( ECHO. ECHO ------------------------ No files or folders to processs ------------ ECHO No file or folder detected ECHO Press any key to exit and restart again ... pause>nul & exit /B 0 ) REM change to working directory pushd "%~dp1" REM ECHO Current working directory: %CD% ECHO. REM Test if FIRST parameter is a file or directory set ATTR=%~a1 set DIRATTR=%ATTR:~0,1% if /I "%DIRATTR%"=="d" ( ECHO First parameter is a folder: "%~n1%~x1" ECHO. goto next ) if /I "%DIRATTR%"=="-" ( ECHO First parameter is a file: "%~nx1" ECHO. goto next ) pause :next REM Remove absolute path SET FOLDER=%~n1%~x1 ECHO Folder/file attributes of above: %~a1 ECHO. REM Use pushd to cd to parent directory REM (workaround for UNC path to network drives) SET PARENT=%~1\.. pushd "%PARENT%" ECHO Delete from: %CD% ECHO. ECHO Delete the following files and/or folders^(all dragged and dropped items^)? FOR %%e in (%*) do ECHO %%~nxe ECHO. :begin ECHO To quit, press X on on this window or use CTRL + C ... ECHO. ECHO Press any key to delete the above file^(s^) and/or folder^(s^) ... PAUSE >NUL ECHO. REM Create an empty directory MKDIR "%~dp0EmptyDir" set count=0 :Loop REM test parameters on each loop to identify folders from files IF [%1]==[] goto continue set ATTR=%~a1 set DIRATTR=%ATTR:~0,1% if /I "%DIRATTR%"=="d" ( REM Add >NUL to end of below command to prevent output to STDOUT robocopy "%~dp0EmptyDir" "%~1" /MIR /W:0 /R:0 ECHO Deleted folder: "%~nx1" ECHO. RMDIR /Q/S "%~1" ECHO. ) else ( DEL /F/Q "%~1" REM Uncomment below to ECHO deleted files REM ECHO Deleted file: "%~nx1" ) :endloop set /A count+=1 SHIFT goto Loop :continue ECHO Files and/or Folders processed: %count% popd popd If exist "%~dp0EmptyDir" RMDIR /Q "%~dp0EmptyDir" ECHO. ECHO -------------------------- closing batch file -------------------------- ECHO. Endlocal ECHO. call:errorfunc ECHO. REM --------------------- Exit options (default is paused exit) ------------- REM Uncomment below to exit now REM goto end REM Uncomment below to use delayed exit REM goto delayedexit REM ---------------------------- Paused exit -------------------------------- ECHO.&ECHO.Press any key to end the application ... Pause>NUL&Goto:end REM ---------------------------- Delayed Exit -------------------------------- :delayedexit REM Sets exit code to 0 ECHO exiting in 10 seconds..........&ECHO. ECHO hit PAUSE on keyboard to pause... any key will resume exit FOR /l %%a in (10,-1,1) do (TITLE %title% -- closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL) Title Press any key to exit . . .&ECHO.&EXIT /B 0 REM ------------------------------ exit now --------------------------------- :end EXIT /B 0 REM -------------------- Function Section (outside of local) ---------------- :errorfunc ECHO The exit error code is: %ERRORLEVEL%, errorlevel will be reset to 0 on exit goto :eof