views:

59

answers:

5

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?

A: 

This might seem obvious, but does DGAVCIndex.exe exist on the Win7 machine at the specified location?

Borealid
Yes, it does. I copied and pasted it directly from Explorer.
Hugh Guiney
A: 

Are you sure the folder names are correct with respect to the 32 bit and 64 bit versions of Windows 7. Did you check whether your batch file exists in the location that you have mentioned in the bat file.

ckv
I'm not quite sure what you're asking... I only have the 64 bit version of Win7. The file exists at the location in the batch file.
Hugh Guiney
+2  A: 

You might want to use %PROGRAMFILES% instead of hard coding "c:\program files" into your batch file. For 64bit windows, there's also %PROGRAMFILES(x86)% which points to the 32bit program files directory.

Larry Osterman
Thanks for the suggestion, but it's not relevant to the problem.
Hugh Guiney
Bummer. I was hoping that it might be a subtle spelling error.
Larry Osterman
A: 

Explorer mimics some directories like "C:\Program Files" and "C:\Users". When you use a localized windows 7, the directories have still the same name, but Explorer displays something localized like "C:\Programme" or "C:\Bemutzer".

Dont trust Explorer use the command line for copying files on a location you want to specify.

harper
My Windows 7 is localized to US English; the Explorer path and the command line path are exactly the same. That's not the problem.
Hugh Guiney
A: 

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
)
Helen
That did it; thank you!
Hugh Guiney