I have a file structure like this:
d:\temp\random1\index.html d:\temp\random2\index.html d:\temp\random3\index.html
and I want to get list paths in python. Thus, the output will be:
files = ['path': 'd:\temp\random1\index.html', 'directory': 'random1']
I am using code like this:
files = [] for dirpath, dirnames, filenames in os.walk('D:\\temp'): for fname in filenames: if fname.endswith(".md"): path = os.path.join(dirpath,fname) files.append({'path':path,'directory': dirpath})
but I cannot figure out how to get the directory values. I get with this code:
files = ['path': 'd:\temp\random1\index.html', 'directory': 'd:\temp\random1\']
How to get a directory without any dirty hacks?
source share