逐步删除目录,之前不计算全部

delete directories step by step without calculate the whole amount before

我有一个局域网硬盘,上面有数百万个我要删除的文件。但是每次我调用删除函数(Windows-Explorer 或 rmdir)时,系统都会在删除任何文件之前计算死亡。所以我正在寻找一种自动删除文件和目录的方法,即席迭代。

我创建了一个批处理文件来处理上述功能。所以我可以启动脚本,它会临时删除文件。即使我必须暂停,我也可以中止脚本并稍后在我之前取消脚本时继续处理:

@echo off
set OFFSETDIR="%1"
if "%OFFSETDIR%"=="" goto HELP
pushd %OFFSETDIR%
cd /d %OFFSETDIR%
set OFFSETDIR="%cd%"

:PSUBDIR
for /f "tokens=*" %%D in ('DIR /A:D /b') do (
pushd "%%~fD"
goto PSUBDIR
)
echo [INFO] erase /F /Q "%cd%\*"
erase /F /Q "%cd%\*"
if errorlevel 1 goto ANYERROR
if "%cd%"==%OFFSETDIR% goto PEND
set LASTSUBDIR="%cd%"
popd
echo [INFO] rmdir /q %LASTSUBDIR%
rmdir /q %LASTSUBDIR%||rem
if errorlevel 1 goto ERASEHIDDEN
goto PSUBDIR

:ERASEHIDDEN
echo [WARNING] there was an error when trying to rmdir %LASTSUBDIR%
echo [WARNING] this may be in cause of existing hidden files in the directory. so...
echo [INFO] erase /F /Q /A:H %LASTSUBDIR%\*
erase /F /Q /A:H %LASTSUBDIR%\*
if errorlevel 1 goto ANYERROR
echo [INFO] hidden files erased successfully. second try for rmdir %LASTSUBDIR%
rmdir /q %LASTSUBDIR%||rem
if errorlevel 1 goto ANYERROR
goto PSUBDIR

:ANYERROR
echo [ERROR] the script has cancelled due to an unhandled error
popd
goto SEND

:PEND
echo [INFO] the script has successfull ended
popd
goto SEND

:HELP
echo [INFO] A little script to erase iterative recursivley files and directories.
echo [INFO] Usage: %0 PATH_TO_DELETE
echo [INFO] the script will delete all files an directories below the given path.
echo [INFO]
echo [INFO] directories will be erased with rmdir /q
echo [INFO] /q supresses the user-confirmation
echo [INFO] files will be erased with erase /f /q
echo [INFO] /f means to delete also readonly-files
echo [INFO] /q supresses the user-confirmation
echo [INFO] when the rmdir will fail, there's a second try to erase also hidden files
echo [INFO] with option /a:h

:SEND
echo.