删除目录及其文件中使用的命令行,但不要抛出错误,如果它不存在 [英] Delete a directory and its files using command line but dont throw error if it doesnt exist
本文介绍了删除目录及其文件中使用的命令行,但不要抛出错误,如果它不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个Windows命令来删除一个目录及其包含的所有文件,但我不希望看到任何错误,如果该目录不存在。
I need a Windows command to delete a directory and all its containing files but I do not want to see any errors if the directory does not exist.
这当然是很容易的......
Surely this is easy enough...
推荐答案
重定向输出的删除
命令NUL:
Redirect the output of the del
command to nul:
del {whateveroptions} 2>nul
你也可以删除
之前调用检查文件的存在:
Or you can check for file existence before calling del
:
if exist c:\folder\file del c:\folder\file
请注意,您可以使用是否存在C:\\文件夹\\ NUL
或只是是否存在C:\\文件夹\\
(与尾随 \\
),以检查是否 C:\\文件夹
的确是一个文件夹,而不是一个文件
Note that you can use if exist c:\folder\nul
or just if exist c:\folder\
(with the trailing \
) to check if c:\folder
is indeed a folder and not a file.
这篇关于删除目录及其文件中使用的命令行,但不要抛出错误,如果它不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文