Frage

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?

War es hilfreich?

Lösung

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".

Andere Tipps

There's a simple way:

  1. move your file to any directory you like, (move)
  2. delete all files, (del *. * /f)
  3. move your file back. (move)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top