批次-获取“目录不为空"在rmdir命令上 [英] Batch - Getting "The directory is not empty" on rmdir command

查看:184
本文介绍了批次-获取“目录不为空"在rmdir命令上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作批处理脚本,脚本的一部分试图删除目录及其所有子目录.我收到有关子目录不为空的间歇性错误.我读了一篇有关索引是罪魁祸首的文章.我禁用了WSearch,但最终还是得到了错误.

I am making a batch script and part of the script is trying to remove a directory and all of its sub-directories. I am getting an intermittent error about a sub-directory not being empty. I read one article about indexing being the culprit. I disabled WSearch but I eventually got the error again.

rmdir /S /Q "C:\<dir>\"

推荐答案

我遇到了与哈里·约翰斯顿(Harry Johnston)提到的相同的问题. rmdir /s /q会抱怨目录不是空的,即使/s是要为您清空的!我个人认为这是Windows中的错误.

I experienced the same issues as Harry Johnston has mentioned. rmdir /s /q would complain that a directory was not empty even though /s is meant to do the emptying for you! I think it's a bug in Windows, personally.

我的解决方法是先删除目录中的所有内容,再删除目录本身:

My workaround is to del everything in the directory before deleting the directory itself:

del /f /s /q mydir 1>nul
rmdir /s /q mydir

(1>nul隐藏del的标准输出,因为否则,它将列出它删除的每个文件.)

(The 1>nul hides the standard output of del because otherwise, it lists every single file it deletes.)

这篇关于批次-获取“目录不为空"在rmdir命令上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆