我有一个局域网硬盘,我将删除数百万个文件。但每当我调用删除功能(Windows-Explorer或rmdir)时,系统会在删除任何文件之前计算死亡。所以我正在寻找一种自动删除文件和目录的方法。
答案 0 :(得分:0)
我已经为我创建了一个处理上述功能的批处理文件。所以我可以启动脚本,它会删除临时文件。即使我必须暂停,我也可以中止脚本并在稍后的时间继续进行处理,之后我取消了脚本:
@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.