I have a question about fnmatch function. Can fnmatch take a list return from a function for the pattern? Consider the following code.

import os
import sys
import time
import fnmatch
import shutil
from logalert import log

def copyLiveToPrompt():
#This function will copy all of the appropriate Voice Prompt files from LivePrompts #directory to promptDir based on promptList
	try:
	   os.chdir(SourceDir)
	   for filename in fnmatch.filter(os.listdir(SourceDir), 'promptList':
	       shutil.copy(filename, "DestinationDir/new-%s" % filename)
	   return
	except Exception as error:
		log(logFile, 'An error has occurred in the copyLiveToPrompt function: ' + str(error))
		raise

Thank you for your time!

Recommended Answers

All 2 Replies

Are you really only interested files named "promptList"? Why use fnmatch then?

Yes, I'm only interested in files in promptList and fnmatch is the closest I can get. Is there other way to do this?

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.