Hi folks! This is my first python script! It will be executed within AvsP, which is an application for writing AviSynth scripts. It provides a full Python interface, for macros and other operations.

Here's the code I have now:

# batchCreateD2Vs
# by Derek Prestegard
# Last Modified 4/3/08
#
# This python script works through a directory, and generates a d2v for all
# VOB and MPG files encountered. It will not extract audio, and it will 
# honor pullown flags

# Changelog:
# r001 4/3/08 - 4:47 PM - Initial script

import os
import fnmatch

# Get the directory containing source files
dirname = avsp.GetDirectory()

# Create a BAT file
f= open('batchDecode.bat', 'w')

if dirname:
    # Generate each of the d2v files
    for filename in os.listdir(dirname):
        fullname = os.path.join(dirname, filename)
        if os.path.isfile(fullname):
            # Only work on VOBs and MPGs (for now)
            if fnmatch.fnmatch(filename, '*.vob'):
               # Build the DGIndex command string
               indexStr = 'dgindex.exe -IF=[' + fullname + '] -FO=0 -OM=0 -OF=[' + fullname + '] -MINIMIZE -EXIT \n'
               # Write the string to a BAT file
               f.write(indexStr)
            if fnmatch.fnmatch(filename, '*.mpg'):
               # Build the DGIndex command string
               indexStr = 'dgindex.exe -IF=[' + fullname + '] -FO=0 -OM=0 -OF=[' + fullname + '] -MINIMIZE -EXIT \n'
               # Write the string to a BAT file
               f.write(indexStr)
f.close()

I know, its ugly :) I'm no programmer. It's complaining about line 26, which is:
if fnmatch.fnmatch(filename, '*.vob'):

From my understanding, this line should evaluate whether "filename" ends in .vob.

I want my script to operate on VOBs and MPGs, so if I can combine that into a single IF statement, that would be ideal.

I welcome your input!

Thanks,
~MiSfit


I know, its ugly :) I'm no programmer. It's complaining about line 26, which is:
if fnmatch.fnmatch(filename, '*.vob'):

And what does he say (Which exception is thrown) ?

Use endswith. fnmatch is specific to *nix (I think) and so won't work if you are using MS Windows.

if os.path.isfile(fullname):
     # Only work on VOBs and MPGs (for now)
     if filename.endswith('.vob') or filename.endswith('.mpg'):
         f.write('dgindex.exe -IF=[%s] -FO=0 -OM=0 -OF=[%s] -MINIMIZE -EXIT \n' % \
                   (fullname, fullname))
##
##   You could also slice off the end if you have a lot of different endings
ending_tuple=( ".mpg", ".vob" )
ending = filename[-4:]
if ending in ending_tuple:
     ##write to file
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.