I am trying to recursively iterate through folders to assign a particular file to a variable for later parsing, however I am receiving the following error:
TypeError: argument of type 'PosixPath' is not iterable
Flask version 1.0.2 (not sure if its relevant)
Python version 3.7.3
Imports:
from pathlib import Path
from glob import glob
Code:
def parse_info(bundle_path):
file_list = []
for filename in Path(bundle_path).glob('**/*.*'):
file_list.append(filename)
for elem in file_list:
if 'uname' in elem:
print('present')
Call:
parse_info(<some path>)
The 'print(filename)'
does print out all the files in that path and the desired search string is present in that print output, so I know it exists, however just not sure how to capture that element for later. Any help would be appreciated.
The answer in this case was to cast the filename to a string when appending it to the list:
file_list.append(str(filename))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With