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

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

$
0
0

You can use os.listdir coupled with os.path.isdir for this.

Enumerate all items in the directory you want and iterate through them while printing out the ones that are directories.

import oscurrent_directory = os.path.dirname(os.path.realpath(__file__))for dir in os.listdir(current_directory):    if os.path.isdir(os.path.join(current_directory, dir)):        print(dir)

Viewing all articles
Browse latest Browse all 5

Trending Articles



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