首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按步骤删除目录,不计算之前的全部金额

按步骤删除目录,不计算之前的全部金额
EN

Stack Overflow用户
提问于 2018-01-13 20:55:19
回答 1查看 48关注 0票数 0

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-13 20:56:05

我已经创建了一个处理上述特性的批处理文件。因此,我可以启动脚本,它将临时擦除文件。即使我不得不暂停,我也可以中止脚本,并在稍后继续之前我取消脚本时的处理:

代码语言:javascript
复制
@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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48240062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档