0

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.

  1. How to also add the data from mediainfo to both workinglist.txt and database.txt without needing another (slow) mediainfo query?

  2. How do I split that one long line of code to another line or few to make it easier to read and manage?

Bricktop
  • 533
  • 3
  • 22
  • what about `findstr ... >> workinglist || ( mediainfo ... >> workinglist & mediainfo ... >> database)` – Nahuel Fouilleul Sep 08 '21 at 15:04
  • a mediainfo query makes the script very slow and doing it twice would be twice as slow. – Bricktop Sep 08 '21 at 15:10
  • 2
    or `findstr ... >> workinglist || for /f %%c in ('mediainfo ...') do ( echo %%c >> workinglist & echo %%c >> database )` ? to avoid executing mediainfo twice – Nahuel Fouilleul Sep 08 '21 at 15:10
  • @NahuelFouilleul not sure how to set the options for the additional ```for``` loop for it to be correctly displayed. wanna format it as an answer? – Bricktop Sep 08 '21 at 15:25
  • 2
    It would help if you showed a few lines of `workinglist.txt` and `database.txt`. – lit Sep 08 '21 at 15:58
  • @lit they are both supposed to read like ```d:\path to\media file.mp4|67382943|627843.48300```, as in ```path-to-file|bytes|duration``` but it only works with OP code. – Bricktop Sep 09 '21 at 03:21

1 Answers1

1

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"
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • works well on most files but I sometimes get error "The process cannot access the file because it is being used by another process.", I think it may be due to special characters in filenames. Investigating now. – Bricktop Sep 11 '21 at 09:43