The batch file runs on Windows Vista; Results in & ldquo; File Not Found & rdquo; on Windows 7

advertisements

The following batch file, meant to parse a directory and send each file to the specified program, works in Windows Vista x64:

@ECHO OFF

FOR /F "tokens=1,2 delims=." %%A IN ('dir /b /on *.mts') DO (
    "C:\Program Files (x86)\DGAVCDecode\DGAVCIndex.exe" -i %%A.%%B -o %%~nA.dga -f 2 -a -e
)

In Windows 7 x64, cmd returns "File Not Found"—both as a normal user and Administrator. What's going on?


I see the following problems in your code:

  1. Looks like you use tokens=1,2 delims=. to split the file name by dot into the base name and extension and then join them back as %%A.%%B. This won't work with file names that contain dots, because it captures only the first two tokens from the file name. For example, given the file name foo.bar.mts, %%A.%%B will expand to foo.bar.

    Moreover, this split/join isn't actually needed. If you use the loop without any parsing options, the file name is stored in the loop variable so that you can simply use that variable instead of %%A.%%B.

  2. You need to enclose the file names passed to DGAVCIndex.exe in quotes, in case they contain spaces.

  3. Also, I second Larry's suggestion to use %PROGRAMFILES(x86)% instead of C:\Program Files (x86) — it never hurts to use predefined environment variables instead of hard-coding standard system paths.

So, your code should look like this:

@echo off

for %%f in (*.mts) do (
  "%ProgramFiles(X86)%\DGAVCDecode\DGAVCIndex.exe" -i "%%~f" -o "%%~nf.dga" -f 2 -a -e
)