How to call IF - ELSE IF condition in a Windows batch script? -


we have hundreds of *.pdf files in folder. each *.pdf have naming convention abc_100_filename.pdf or abc_200_filename.pdf or abc_300_filename.pdf.

in batch script call *.exe file follows:

call test.exe 100  filename call test.exe 200  filename call test.exe 300  filename 

as there no if condition validate file, incorrectly load files incorrect id.

expected result: test.exe 100 should called file abc_100_testfile.pdf.

we mistakenly call test.exe 200 instead of file execution.

how write if - else if condition call .exe file in batch script.

if %str1:~0,7%==abc_100 (call test.exe 100 filename) pause if %str2%==abc_200 (call test.exe 200 filename) 

  • there no need call .exe
  • provided number pass test.exe enclosed in _ use parsing for.

@echo off /f "tokens=1-2* delims=_" %%a in (     'dir /b/a-d "*_*_*.pdf"' ) test.exe %%b "%%a_%%b_%%c" 

a file name fixed structure delimiting elements distinct chars can parsed /f (see ss64.com/nt/for_f) distributing delimited tokens adjacent variable.

 file         abc_100_filename.pdf delims          _   _ tokens        1 _ 2 _ * (rest) variable %%a %%b %%c 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -