Quantcast
Channel: Get name (not full path) of subdirectories in python - Stack Overflow
Browsing latest articles
Browse All 5 View Live

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

import osdirList = os.listdir()for directory in dirList: if os.path.isdir(directory): print('Directory Name: ', directory) print('File List: ', os.listdir(directory))

View Article



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

Splitting your sub-directory string on '\' should suffice. Note that '\' is an escape character so we have to repeat it to use an actual slash.import os#Get directory where this script is...

View Article

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

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...

View Article

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

Use os.path.basenamefor 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:",...

View Article

Get name (not full path) of subdirectories in python

There are many posts on Stack Overflow that explain how to list all the subdirectories in a directory. However, all of these answers allow one to get the full path of each subdirectory, instead of just...

View Article

Browsing latest articles
Browse All 5 View Live




Latest Images

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