1

I have three different file extensions that are used with a command line program. The syntax of this program is program.exe file1.bm file1.pal file1.ppm.

It takes file1.bm and file1.pal and converts them into the ppm file.

I've tried using for %%A in (.bm .pal .ppm) do call program.exe %%A, but it won't work because %%A can't represent all three extensions.

How do I create a batch file using FOR (or an alternative) to fill in the required commands for the above syntax?

Thanks

5
  • 1
    (*.bm *.pal *.ppm) you were searching for files without names. That is legal but Explorer won't let you create them. If using a path you must specify the path before each filename. (C:\*.bm C:\*.pal C:\*.ppm). It works with the dir and del commands too. Commented Mar 12, 2018 at 9:22
  • Windows' filenames are to the left of the LAST dot, and the extension to the right of the LAST dot. Other dots are just part of the name and aren't special. Commented Mar 12, 2018 at 9:28
  • That doesn't answer the question. Even if I use the directory of each file, what commands do I use after "do call program.exe" Commented Mar 12, 2018 at 11:22
  • Once one of the files is found, what is it that needs to be done? Commented Mar 12, 2018 at 14:31
  • I'm trying to use wildcards in the batch program to automate the process of having to type out every single file. There are hundreds of *.bm and *.pal files I need to convert into *.ppm. I have to use the syntax of "bm2ppm file1.bm file1.pal file1.ppm" to convert each file into that ppm format. How is this accomplished in a batch file? This is all im asking. Commented Mar 12, 2018 at 16:42

2 Answers 2

2

You can use for /F and dir /B to get the desired result. First we get every file matching a pattern (*.bm), check if the other file exist, then execute the command.

for /F "tokens=*" %%F IN ('dir /B *.bm') DO (
    %== Found a file to work with ==%
    if exist "%%~nF.pal" (
        %== Validated other file ==%
        bm2ppm "%%~F" "%%~nF.pal" "%%~nF.ppm"
    )
)

Be aware though, if you have special characters in your filename you would need to adjust your codepage using chcp Codepage

If you dont mind having it search recursively, you can use for /R %%F IN (*.bm) DO ( instead.

Make sure to look through for /? and dir /?

Sign up to request clarification or add additional context in comments.

Comments

0
set "passNum=0"
set folder=c:/xxxxxx/

For %%f in ("%folder%\*.bm") Do (
    set /a "passNum+=1"
)
For %%f in ("%folder%\*.pal") Do (
    set /a "passNum+=1"
)
For %%f in ("%folder%\*.ppm") Do (
    set /a "passNum+=1"
)

if %passNum% == 3 (
    rem  do converts them into the ppm file.
)

Using FOR in a batch file with multiple files with multiple extensions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.