问题描述
我对此有疑问.我一直在尝试各种不同的方法,但这是我得到的最接近的方法.我正在尝试删除具有多个子目录的目录中具有特定文件扩展名的所有文件.但是我想防止一个文件被删除.以下是我所拥有的:
I am having issues with this one. I have been trying all kinds of different methods but this is the closest I got. I am trying to delete all files with a certain file extension in a directory which has multiple sub directories. But I want to keep one file from being deleted. Below is what I have:
For /R "%userprofile%\AppData\Local\Microsoft\Internet Explorer\DOMStore" %%i in (*.xml) DO if not %%i==10.10.5[1].xml echo del /q %%I`
如何正确执行此操作?
推荐答案
由于for /r
将完整文件名传递给元变量 %%i
,所以匹配永远不会成立.
since for /r
delivers the full filename to the metavariable %%i
then the match will never be true.
使用if not %%~nxi==10.10.5[1].xml
仅处理名称和扩展名.
元变量是批处理区分大小写的少数几个领域之一.所有对元变量的引用都必须使用相同的大小写.
The metavariable is one of the few areas where batch is case-sensitive. All references to the metavariable must be in the same case.
如果要删除的完整文件名可能包含空格(或其他分隔符/毒药字符),则删除目标应为"quoted"
.
If the full-filename to be deleted may contain a space (or other separators/poison characters) then the delete target should be "quoted"
.
这篇关于Windows批处理脚本,删除除一个文件外的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!