문제

I am trying to make a batch file to look for file names based on a list I have in a text file (one file name per line without an extension )
The batch file needs to search in a folder+subfolders and output the files it DIDN'T FIND to a text file (Missing.txt)`

echo off
for /f "tokens=*" %%i in (Filelist.txt) DO echo %%i>InList.txt
(
IF NOT EXIST %%i (echo %%i>Missing.txt) 
) 

ok so now InList.txt have all the file names from Filelist.txt regardless if they exist or not
and Missing.txt has %i in the file

ok so this is the code i used to solve my problem @echo off for /f "tokens=*" %%i in (Filelist.txt) DO ( IF EXIST %%i.* (echo %%i>>InList.txt) ELSE echo %%i>>Missing.txt )

my filenames inside Filelist.txt had no extensions so i added .* after the %%i in the IF statement but if your filelist has extensions you can use the solution below

도움이 되었습니까?

해결책

You've misunderstood the format of a for loop. You also need to use >> to append to a text file, instead of > which will write over the file. Going off of your original logic, where InList.txt will contain all files, and Missing.txt will only contain missing files:

@echo off
for /f "tokens=*" %%i in (Filelist.txt) DO (
    echo %%i>>InList.txt
    IF NOT EXIST %%i (echo %%i>>Missing.txt) 
) 

But if InList.txt should only contain files that do exist:

@echo off
for /f "tokens=*" %%i in (Filelist.txt) DO (
    IF EXIST %%i (echo %%i>>InList.txt) ELSE echo %%i>>Missing.txt
) 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top