Need to exclude certain files from the entire folder using a whitelist text file

StackOverflow https://stackoverflow.com/questions/20835818

  •  22-09-2022
  •  | 
  •  

문제

I'm having a problem with excluding certain files from the entire folder with using a whitelist text file. Currently I'm working on batching scripting

for /f "tokens=* Delims=" %%x in (whitelist.txt) do
(
  for %%i in ("list\*") do 
  (
   if not "%%i"=="%%x" 
   (
   echo %%i
   )
 )
)

Need some guidance here thanks.

도움이 되었습니까?

해결책

You are iterating the directory for each line in whitelist.txt

Whithout knowing what is in whitelist.txt, this is an aproximation to the problem

inside whitelist.txt

one.txt
two.txt
this is data.txt

Then you can do something like

for /f "tokens=*" %%f in (
    'dir /b ^| findstr /v /b /e /i /l /g:whitelist.txt'
) do echo %%f

Generate the listing of files (and folders, if you want to exclude them, add /a-d to dir command) getting only the filenames (/b), and filter with findstr. Parameters are : take the search strings from whitelist.txt (/g:whitelist.txt), content of whitelist.txt are literal strings (/l), ignore case (/i), search strings should match from begin (/b) to end (/e) of line, and only return lines not matching (/v).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top