1

I 'm currently writing a to execute an unknown named checksum file in a directory. The problem is that I have no idea how to search for an .sfv or .md5 in a directory and set the found checksum file as a variable which I can execute later on in the script.

@echo off
set quicksfv="%ProgramFiles%\QuickSFV\quicksfv.exe"

if exist "*.sfv" (
    goto sfvcheck
    )
    and (
    set EXT="sfv"
)
else (
    goto skip
)
if exist "*.md5" (
    goto sfvcheck
    )
    and (
    set EXT="md5"
)
    else (
    goto skip
)
/*
this is what i would like to add if the checksum file exist
*/

GetFileName of checksum file
set CHECKSUM="checksumfilename"

:sfvcheck
quicksfv "%CHECKSUM%.%EXT%"

:skip
echo. No checksum file was found!
pause
exit
Compo
  • 36,585
  • 5
  • 27
  • 39
Hetsig
  • 29
  • 5
  • 5
    Type `if /?` into a command prompt window and learn how to use `if`/`else`; and there is no `and` command... – aschipfl Jun 22 '19 at 20:48
  • 1
    Open a command prompt window and run `for /?`. The output help could be useful to understand a command line for usage in a batch file like `@set "FileFound=" & (for %%I in (*.sfv *.md5) do @"%ProgramFiles%\QuickSFV\quicksfv.exe" "%%I" & set "FileFound=yes") & if not defined FileFound echo No check sum file was found!` being a replacement for your batch file. See also [single line with multiple commands using Windows batch file](https://stackoverflow.com/a/25344009/3074564). Let me know if I should write an answer and explain in detail how this command line replaces your entire batch file. – Mofi Jun 23 '19 at 17:52
  • @aschipfl the if help section doesn't provide an answer to my question, or i can't find it. it does have some helpful information about filenames but in my case the filename is unknown. the correct way would be ```if exist "*.sfv" ( set EXT=sfv goto sfvcheck )``` @Mofi thank you for the for help section. i noticed that for /R could help me alot in executing subdirectories of checksum files! also found some great information about tokens and delim that i've used before but always trialed and errored. i'll try your method and come back! thank you again :). – Hetsig Jun 25 '19 at 17:38
  • @Mofi thank you so much for the helpful for information and the line of example code. made a bat in a directory with a checksum file and it worked like a charm! the single line thing i learned after this post but your version helped me understand combining them a bit better. although while writing i find multiple lines to be more readable and easier to debug but for a final take i will definitely single line most of the commands. i do not know how to mark an answer as correct but... – Hetsig Jun 25 '19 at 17:48
  • to make it work as a right click bat script edit to this ```(for %%I in (%1\*.sfv *.md5)``` – Hetsig Jun 25 '19 at 18:02
  • @Hetsig `for %%I in (%1\*.sfv *.md5)` is not good. Better would be `for %%I in ("%~1\*.sfv" "%~1\*.md5")` to process all `*.sfv` and `*.md5` files in directory passed to the batch file with using surrounding `"` like `"C:\Temp\Development & Test"` or with surrounding double quotes like `C:\Temp\DevelopmentAndTest`. Run `call /?` for help on using arguments passed to a batch file. You will see the output is similar to parts of __FOR__ help. It would be also possible to use `for /R "%~1" %%I in (*.sfv *.md5)` for a recursive search in passed directory and all its subdirectories. – Mofi Jun 25 '19 at 18:48
  • thank you @Mofi ! i do use echo on for debugging and switching it to off for running. there's a lot of things flying then but if i use "set %1" as a manual cmd line before running the .bat it won't close that easily. i still can't figure out how to mark your answer as correct :/. – Hetsig Jul 23 '19 at 18:16

1 Answers1

0

I did this process a bit different with another CRC application. It only supports SFV but...

@echo off

set SFVCHECK="C:\dont_alter\pure-sfv.exe"
cd %1
set errorlevel=0
%SFVCHECK% -t -i
if errorlevel 10 (
    echo Different CRC or a missing file...
    pause
    exit /B %errorlevel%
    )
if errorlevel 11 (
    echo Different CRC...
    pause
    exit /B %errorlevel%
    )
if errorlevel 12 (
    echo Missing file...
    pause
    exit /B %errorlevel%
    )
    ```
Hetsig
  • 29
  • 5