Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: pball
I made a script to compared the crc in a file name to the actual crc of a file. There is a txt file with a file name then the files crc on each line. The script finds the crc in the file name and compares it to the actual crc.
Example of a line from the file.
[a-s]_blood;_the_last_vampire__killerhis__[f6d0e757].mkv F6D0E757----------------------------------------------------------------------
@echo offsetlocal enabledelayedexpansion
echo drag and drop sfv onto window
set /p settings=
clsfor /f "usebackq tokens=*" %%x in (%settings%) do (
set line=%%x
set crc=!line:~-8!
set filename=!line:~0,-9!call :check !filename!
if /I not "!z:~0,8!" == "!crc!" (
echo -
echo !filename!
echo !crc!
echo -
)
set z=
)goto end
:check
set x= %1%2%3
:againif "%x:~-1%" == "[" set s=%z% & goto :EOF
set z=%x:~-1%%z%
set x=%x:~0,-1%
goto again
:end
pause----------------------------------------------------------------------
The script works so far but it returns many false positives, which I believe is due to characters in the file names. I believe ; , & are some characters throwing it off.
I found changing set x= %1 in the first line of the check subroutine to set x= %1%2%3 eliminates the false positive that include ; and , in the file name. Do those characters cause the script to think the file name is multiple strings instead of one?

thanks very helpful
well I found out after some searching that ^ is an escape character so i replaced any instance of & in the filename var like this set filename=!filename:^&=.!
Anyone know of anyway to speed this up? Such as a way to extract the crc from the file name instead of checking each character from the end of the file backwards?

Since your using delayed expansion anyway try changing all of your variables to use !exclaimationmarks!, doing so should escape all the special characters.
As for "set x= %1%2%3" try using:
for %%a in (" %~1%~2%~3") do set x=%%~aIt shoul escape the special characters in the parameters.

Anyone know of anyway to speed this up?
Use any other language?VBScript:
Set fso = CreateObject("Scripting.FileSystemObject") For Each f In fso.GetFolder(".").Files If LCase(fso.GetExtensionName(f)) = "sfv" Then _ ParseSFV fso.OpenTextFile(f) Next 'f Sub ParseSFV(sfv) Do Until sfv.AtEndOfStream line = sfv.ReadLine s = InStrRev(line, " ") If s Then crc = Mid(line, s + 1) line = Left(line, s) If InStr(1, line, crc, 1) = 0 Then _ WScript.Echo "CRC mismatch: " & line End If Loop End Sub

thanks for the vbs script. How could you have the mismatch ones echoed to a window instead of separate popups? Having separate popups is a bit of a pain.
also how would you make it ignore lines that start with ;

How could you have the mismatch ones echoed to a window instead of separate popups? Having separate popups is a bit of a pain.
Normally, I'd be willing to tell you to just use cscript, but I've been thinking about DHTML, so WTH, I might as well wrap it in a HTApplication.
SFV.HTA:<html> <head> <hta:application applicationName="SVFCheck" /> <title>SFV Checker</title> <style type="text/css"> body { background: #CCFFCC } </style> <script language="vbscript"> Sub Main() window.resizeTo 700,500 Set outList = document.createElement("ul") document.body.appendChild outList Set fso = CreateObject("Scripting.FileSystemObject") For Each f In fso.GetFolder(".").Files If LCase(fso.GetExtensionName(f)) = "sfv" Then Set out = document.CreateElement("li") out.innerHTML = f.Name out.appendChild ParseSFV(fso.OpenTextFile(f)) outList.appendChild out End If Next 'f If document.hasChildNodes(outList) Then _ document.body.style.background = "#FFCCCC" End Sub Function ParseSFV(sfv) 'As ul Set ret = document.createElement("ul") Do Until sfv.AtEndOfStream line = Trim(sfv.ReadLine) s = InStrRev(line, " ") If s And Left(line, 1) <> ";" Then crc = Mid(line, s + 1) line = Left(line, s) If InStr(1, line, crc, 1) = 0 Then Set li = document.CreateElement("li") li.innerHTML = "CRC mismatch: " & line li.title = "Expected: " & crc ret.appendChild li End If End If Loop Set ParseSFV = ret End Function </script> </head> <body onload="Main" /> </html>

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |