我编写了一个小的python代码来读取特定路径中包含 .txt的特定文件。我想做同样的事情来搜索具有多个扩展的文件或多或少使用相同的代码而几乎没有修改。当然,我不是在寻找能够搜索所有扩展的/ 。任何帮助,将不胜感激。
varlogpath = "C:/Users/vveldand/Office/Fetcher/Projects/LOG-PARSER/var/log/*.txt"
outputfile = open(wrfilename, "a")
files=glob.glob(varlogpath)
答案 0 :(得分:0)
wrfilename = os.path.join(wrscriptpath, 'TiC_Timeline_Report.txt')
varlogpath = "C:/Users/vveldand/Office/Fetcher/Projects/LOG-PARSER/var/log/*.txt"
outputfile = open(wrfilename, "a")
files=[glob.glob(varlogpath.replace(".txt",ext)) for ext in list_of_extensions_you_want_to_search]
答案 1 :(得分:0)
files=None
# put file extensions into a list
fileext=[".txt",".log",".csv"]
for ext in fileext:
varlogpath = "C:/Users/vveldand/Office/Fetcher/Projects/LOG-
PARSER/var/log/*"+ext
outputfile = open(wrfilename, "a")
files=glob.glob(varlogpath)