0

I have written a small python code to read specific files containing .txt from the specific path. I would like to do the same thing to search for files with multiple extensions more or less with the same code with little modifications. Ofcourse, I am not looking for / which will search all the extensions. Any help would be appreciated.

varlogpath = "C:/Users/vveldand/Office/Fetcher/Projects/LOG-PARSER/var/log/*.txt"

outputfile = open(wrfilename, "a")
files=glob.glob(varlogpath)  
VRV
  • 1
  • 1

2 Answers2

1

you could do something like this:

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)  
pydvlpr
  • 311
  • 2
  • 6
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]
cosmic_inquiry
  • 2,557
  • 11
  • 23