python script.py --dir C:\\path\\path\\*.* #This should take all files (doesn't matter what type ex 'm', 'xml' 'txt' etc.).
如果用户只想获取 XML 格式的文件,他可以输入“*.xml”,对于 '.m' 文件同理。需要注意的是,如果用户只想获取“XML”或“m”格式的文件,脚本也能找到。
def main(argv):
args = argumentParser(argv)
if args.dirname.endswith('.m'):
overrideM(args)
elif args.dirname.endswith('.xml'):
xmlOverride(args)
elif args.dirname.endswith(('.m', '.xml')): #Can I do like this?
#Here I want to run both of my function.
overrideM()
xmlOverride()
else:
print "Error can't find files"
我的“m”函数(部分内容)
def overrideM(args):
for fileName in glob.glob(args.dirname):
print fileName
with open(fileName, 'r') as searchFile:
my_files_content = searchFile.read()
#...rest of my code
我的“XML”函数(其中一小部分)
def xmlOverride(args):
for fileName in glob.glob(args.dirname):
print fileName
with open(fileName, 'r') as searchFile:
my_files_content = searchFile.read()
#...rest of my code
print(args)
- Rudziankoŭ