Computing.Net > Forums > Programming > SFV File parser in batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

SFV File parser in batch

Reply to Message Icon

Name: pball
Date: April 18, 2009 at 13:07:07 Pacific
OS: Windows XP
CPU/Ram: 2.8 ghz / 2 gig
Product: Home made / NONE
Subcategory: Batch
Comment:

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 off

setlocal enabledelayedexpansion

echo drag and drop sfv onto window
set /p settings=
cls

for /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
:again

if "%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?



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: April 18, 2009 at 19:51:55 Pacific
Reply:

Yes, it does. The ampersand also has special meaning to CMD.


0

Response Number 2
Name: pball
Date: April 18, 2009 at 20:39:43 Pacific
Reply:

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?


0

Response Number 3
Name: Judago
Date: April 18, 2009 at 22:32:01 Pacific
Reply:

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=%%~a

It shoul escape the special characters in the parameters.


0

Response Number 4
Name: Razor2.3
Date: April 20, 2009 at 03:21:45 Pacific
Reply:

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


0

Response Number 5
Name: pball
Date: April 20, 2009 at 13:16:28 Pacific
Reply:

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 ;


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: April 22, 2009 at 11:30:58 Pacific
Reply:

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>


0

Response Number 7
Name: pball
Date: April 22, 2009 at 11:52:51 Pacific
Reply:

Thank you very much.

This type of scripting is very interesting.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: SFV File parser in batch

Compare file names in batch file www.computing.net/answers/programming/compare-file-names-in-batch-file/16616.html

Date Routines in Batch Files www.computing.net/answers/programming/date-routines-in-batch-files/15590.html

%DATE% in batch files with win98 www.computing.net/answers/programming/date-in-batch-files-with-win98/4007.html