Is it possible for a batch file to delete a file i

2019-07-19 05:27发布

问题:

Trying to write a batch file that will loop through all the files in a directory and if the first part of the file is not found in the text file then delete.

In the images directory the files are named like:

1_a.jpg
1_b.jpg
1_c.jpg
2_a.jpg
3_a.jpg
3_b.jpg

in the file the list is

2
3

So at this point I would like to delete

1_a.jpg
1_b.jpg
1_c.jpg

Started by using:

@echo off
wget -N http://www.domain.com/imagelist.txt
FOR /R C:\image-directory\ %%G IN (*.jpg) DO ??????? %%G

And im stuck.

回答1:

@echo off
setlocal
set "folder=c:\somePath"
set "excludeFile=c:\somePath2\someFile.txt"
for /f "eol=: delims=" %%F in ('dir /b /a-d "%folder%" ^| findstr /vibg:"%excludeFile%"') do del "%folder%\%%F"