Quantcast
Channel: Get name (not full path) of subdirectories in python - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by nosklo for Get name (not full path) of subdirectories in python

$
0
0

Use os.path.basename

for path, dirs, files in os.walk(currentDirectory):    #I know none of my subdirectories will have their own subfolders     if len(dirs) == 0:        print("Subdirectory name:", os.path.basename(path))        print("Files in subdirectory:", ', '.join(files))

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>