I have studied this: Is it possible for a batch file to delete a file if not found in list from text file?
In my case there is a list of words (one in each line) in a text file e.g:
ext
abcd
in which there are extensions of the files (like ext
above) or fragments of filenames' bases (like abcd
above).
So, I don't want files like *abcd*
or *ext*
to be deleted (where *
is for any number of any allowed characters) - and I do want to delete any other files from the directory.
I took this code:
for /f "eol=: delims=" %%F in ('dir /b /a-d "SomeFolder" ^| findstr /vibg:"ExcludeFile"') do del "SomeFolder\%%F"
and what I did to it - I deleted /b
option of findstr
(so now it is
...findstr /vig...
- so as I think findstr
shoud try to match strings from the list (.txt file) to any part of the 8.3 filenames in directory. But it does not. It does not exclude files witch matching extensions from deleting, (it deletes for instance antything.ext
despite the string ext
is in the list). Can you help please?
PS Thanks for trailing spaces, it helped - is it possible to use an implication of two conditions e.g a file would be deleted if:
- a part of filename is not on exclude list
- and a file has a specific extension (let's say
.bmp
).
In above example the file 123.xyz
would be deleted because of the first condition (not a part of it is abcd
nor ext
), but would not be actually because of the second condition (it's extension is not .bmp
)?