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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleGet 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