如何使批处理文件删除其自己的目录? [英] How do I make a batch file delete it's own directory?
问题描述
好的,很抱歉,我对此很陌生,但是我试图使我的批处理文件在启动后删除它自己的目录.这是我的文件夹的排列方式:
Okay, I apologize that I am very new at this, but I am trying to make my batch file delete it's own directory after it has been launched. This is how my folders are arranged:
- 文件夹1
- delete.bat
- Folder1
- delete.bat
我的目标是在启动"delete.bat"之后使"delete.bat"删除"Folder1".所以这是我的代码:
My goal is to make "delete.bat" delete "Folder1" after "delete.bat" has been launched. So here's my code:
rd /s /q %~dp0..\Folder1
这似乎可行,但是它只会删除"Folder1"的内容,而不是整个目录本身.我在做什么错了?
This seems like it would work but it only deletes the contents of "Folder1" rather than the whole directory itself. What am I doing wrong?
推荐答案
来自相应的 MSDN链接:
您不能使用rmdir删除当前目录.您必须首先切换到其他目录(而不是当前目录的子目录),然后将rmdir与路径一起使用.
You cannot use rmdir to delete the current directory. You must first change to a different directory (not a subdirectory of the current directory) and then use rmdir with a path.
我想这是您的问题所在,因为批处理文件位于您要删除的目录中.
I guess this is what's going wrong in your case since the batch file is located within the directory that you're trying to delete.
这篇关于如何使批处理文件删除其自己的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!