Reputation: 13
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`
How can I do this properly?
Upvotes: 1
Views: 249
Reputation: 21
There's a simple way:
Upvotes: 1
Reputation: 80213
since for /r
delivers the full filename to the metavariable %%i
then the match will never be true.
Use if not %%~nxi==10.10.5[1].xml
to process just the name and extension.
The metavariable is one of the few areas where batch is case-sensitive. All references to the metavariable must be in the same case.
If the full-filename to be deleted may contain a space (or other separators/poison characters) then the delete target should be "quoted"
.
Upvotes: 1