如何解决“目录不为空"?在批处理脚本中运行rmdir命令时出错? [英] How to solve "The directory is not empty" error when running rmdir command in a batch script?

查看:104
本文介绍了如何解决“目录不为空"?在批处理脚本中运行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. Here's the command:

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.

我的解决方法是在删除目录本身之前,对目录中的所有内容进行 del :

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天全站免登陆