@echo off set tmp1=%temp%\%random%%random%%random%%random%.tmp set tmp2=%temp%\%random%%random%%random%%random%.tmp set tmp3=%temp%\%random%%random%%random%%random%.tmp if "%1"=="-c" ( call :find_files_withhashes !tmp1! if exist !tmp1! ( dir /s /b /a-d>!tmp2! echo Missing: if exist !tmp2! ( cat !tmp1! !tmp2! | sort | uniq -u del !tmp2! ) call :retrieve_hashes !tmp1! !tmp2! call :calculate_hashes !tmp1! !tmp3! del !tmp1! echo. echo Inconsistent: cat !tmp2! !tmp3! | sort | uniq -u del !tmp2! !tmp3! ) ELSE ( echo Missing: dir /s /b /a-d ) ) if "%1"=="-u" ( call :calculate_hashes 'dir/s/b/a-d' !tmp1! if exist !tmp1! ( call :write_hashes_to_files !tmp1! del !tmp1! ) ) if "%1"=="-e" ( call :find_files_withhashes !tmp1! if exist !tmp1! ( call :retrieve_hashes !tmp1! !tmp2! type !tmp2! del !tmp1! !tmp2! ) ) if "%1"=="-l" ( call :find_files_withhashes !tmp1! if exist !tmp1! ( call :retrieve_hashes !tmp1! !tmp2! set x= for /f "delims=" %%i in (!tmp2!) do ( set x=%%i set file=!x:~42! for %%j in ("!file!") do echo !x:~0,40!;!file!;%%~zj ) del !tmp1! !tmp2! ) ) if "%1"=="-a" ( dir /s /b /a-d>!tmp1! call :find_files_withhashes !tmp2! if exist !tmp2! ( cat !tmp1! !tmp2! | sort | uniq -u>!tmp3! cat <!tmp3! >!tmp1! del !tmp2! !tmp3! ) call :calculate_hashes !tmp1! !tmp2! del !tmp1! if exist !tmp2! ( call :write_hashes_to_files !tmp2! del !tmp2! ) ) if "%1"=="-d" ( call :find_files_withhashes !tmp1! if exist !tmp1! ( call :retrieve_hashes !tmp1! !tmp2! set x= for /f "delims=" %%i in ('sort /r ^<!tmp2! ^| uniq -w 40 -d') do ( set x=%%i echo !x:~42! ) del !tmp1! !tmp2! ) ) @echo on @goto :eof :find_files_withhashes %1 rem @return %1 list of files which have hashes set x= for /f "delims=" %%i in ('lads . /s ^| find /i ":sha1"') do ( set x=%%i echo !x:~12,-5!>>%1 ) goto :eof :retrieve_hashes %1 %2 rem @filelist %1 list of files which have hashes rem @return %2 list of files with their hashes (hash<space><space>filename) for /f "delims=" %%i in (%1) do ( for /f "usebackq delims=" %%j in ("%%~i:SHA1") do ( echo %%j %%~i>>%2 ) ) goto :eof :calculate_hashes %1 %2 rem @filelist %1 list of files whichs hashes should be calculated rem @return %2 list of files with their hashes (hash<space><space>filename) set filelist= set counter=0 for /f "delims=" %%i in (%1) do ( set filelist=!filelist! "%%~i" set /a counter+=1 if /i !counter! GEQ 126 ( set counter=0 if NOT "!filelist!"=="" ( sha1sum !filelist!>>%2 set filelist= ) ) ) if NOT "!filelist!"=="" ( sha1sum !filelist!>>%2 ) goto :eof :write_hashes_to_files %1 rem @filelist %1 list of files with their hashes (hash<space><space>filename) set x= for /f "delims=" %%i in (%1) do ( set x=%%i echo !x:~0,40!>"!x:~42!":SHA1 ) goto :eof
Meine Fragen:
1. Sieht jemand eine gute Möglichkeiten, bei mehrfachem Aufruf mit verschiedenen Parametern (klassische Fälle sind (a)dd+(d)uplicate und (a)dd+(l)ist) die Zwischendateien sinnvoll zu recyclen?
2. "sha1sum" erwartet eine Liste von Dateien, diese ist aber durch die Variablengröße beschränkt. Weiß einer, wie man da sinnvoll eine maximale Auslastung erreichen kann? Derzeit hab ich's auch 126*256<32K beschränkt, aber das wird praktisch nie ausgenutzt. Wie kann man sinnvoll die Länge des Inhaltes einer Variablen ermitteln?
3. Kann man auch ohne das FOR-Konstrukt die Dateilänge zu einer Datei ermitteln?
4. Was ich mich schon lange frage: Wie kann ich '!' und '^' in Dateinamen escapen?
5. Sieht irgendwer Fehler, Mängel oder hat gute Ideen für Erweiterungen?