Listing files in a directory recursively - python -
this question has answer here:
- directory listing in python 2 answers
 
i want display file , folder structure recursively in output .
actual structure:
root--|       |       dira--|             |             dirc--file5             file3             file4       file1       file2       dirb--|             |             no file   expected output:
root: file1 file2  root/dira file3 file4  root/dira/dirc file5   root/dirb no file found   i have written following code below. need inputs in how modify required output.
code
import os.path  path = 'c:\\my\\path\\here'  root, dirnames, filenames in os.walk(path):     subdirname in dirnames:         print  subdirname      filename in filenames:         print os.path.join(root, filename)   actual output
dira dirb c:\my\path\here\file1 c:\my\path\here\file2 dirc c:\my\path\here\dira\file3 c:\my\path\here\dira\file4 c:\my\path\here\dira\dirc\file5      
import os  path = 'root' root, dirnames, filenames in os.walk(path):     print root     filename in filenames:         print filename     if not filenames:         print 'no file found'     print      
Comments
Post a Comment