6
Ho una tale struttura di file:os.walk ottenere i nomi delle directory
d:\temp\random1\index.html
d:\temp\random2\index.html
d:\temp\random3\index.html
e voglio ottenere percorsi di lista in Python. Così l'output sarà:
files = ['path': 'd:\temp\random1\index.html', 'directory': 'random1']
Sto usando questo codice:
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})
ma io non riesco a capire come ottenere directory values.All ottengo con questo codice è:
files = ['path': 'd:\temp\random1\index.html', 'directory': 'd:\temp\random1\']
Come ottenere la directory senza alcuni hack sporchi?