Execute a command over multiple files

353 views Asked by At

so I am wanting to convert a large number of files that all have entirely unique names using a SINGLE program that is run through command prompt.

Here is the command for converting one file:

bam2egg.exe Filename.bam Filename.egg

I want it so I can convert a large number of .bam files that all have unique names to .egg files with the same names. I assume you can do this using a batch file or maybe even one command but I am unsure how.

Help appreciated!

1

There are 1 answers

0
croxis On

You will need to use a little command prompt scripting: the for loop. I'm not familiar with windows command prompt but a quick search found me this:

Iterate all files in a directory using a 'for' loop

What that might look like:

for %i in (*) do bam2egg.exe %i converted\%i.egg

In theory this will put your converted files in a subdirectory called "converted" outputted as "Filename.bam.egg".

Seeing as you are using panda3d you can also use a python script:

import glob
from subprocess import call
import os.path
for filename in glob.glob('*.egg'):
    output_path = os.path.join('converted', filename.rstrip('bam') + egg)
    call(["bam2egg", filename, output_path])

This will output your converted files in a a subdirectory called "converted" and the filename will be a more sane "Filename.egg"