Mission: search the drive using variables %folder% and %wildcards%. The files found are compared by path-to-file|filesize to entries in database.txt. If a match is found, it is copied to workinglist.txt and if not, a new entry is created. The point is to use stored %duration% data provided by mediainfo to greatly reduce processing time.
for /r "%folder%" %%a in (%wildcards%) do (
findstr /i /c:"%%a|%%~za" "%appdata%\df\database.txt" >>%appdata%\df\workinglist.txt || mediainfo --output="General;%%CompleteName%%|%%FileSize%%|%%Duration%%" "%%a" >>%appdata%\df\workinglist.txt
)
The problem is that database.txt is supposed to have all possible data, not only the ones dictated by %folder% and %wildcards%, meaning that any new entries need to be added to both the workinglist.txt AND the database.txt files.
How to also add the data from
mediainfoto bothworkinglist.txtanddatabase.txtwithout needing another (slow)mediainfoquery?How do I split that one long line of code to another line or few to make it easier to read and manage?
CodePudding user response:
There are several different ways to solve this problem. This solution uses mediainfo query just once per each new file:
rem Insert data of new files in newEntries.txt file
del newEntries.txt 2> NUL
for /r "%folder%" %%a in (%wildcards%) do (
findstr /i /c:"%%a|%%~za" "%appdata%\df\database.txt" >> "%appdata%\df\workinglist.txt"
if errorlevel 1 (
mediainfo --output="General;%%CompleteName%%|%%FileSize%%|%%Duration%%" "%%a" >> newEntries.txt
)
)
rem Add new entries to both database and workinglist
type newEntries.txt >> "%appdata%\df\database.txt"
type newEntries.txt >> "%appdata%\df\workinglist.txt"
