I am trying to pull folder names from a network drive in Python. For example, if I have a mapped drive U:, I want to go through and grab all the folders in folder "example" from the path \emily\hello\example
.
This is what I have tried so far.
import os
os.chdir('U:')
all_subdirs = [d for d in os.listdir('.') if os.path.isdir(d)]
for dirs in all_subdirs:
dir = os.path.join('\emily\hello\example', dirs)
os.chdir(dir)
current = os.getcwd()
new = str(current).split("\")[4]
print(new)
this causes many errors, and I am having an issue with the syntax of a shared drive on the network vs a folder locally on my computer.
I want to see them in a list so i can read line by line and compare this list to another list.
ps. i don't want the files in the folders, just the folder names in the folder
thanks~!
error message is C:\Users\212582086\AppData\Local\Continuum\Anaconda3\python.exe "C:/Users/212582086/Desktop/Vendor sort/main" Traceback (most recent call last): File "C:/Users/212582086/Desktop/Vendor sort/main", line 6, in os.chdir(dir) FileNotFoundError: [WinError 3] The system cannot find the path specified: '\emily\hello\example\Software Archive'
Process finished with exit code 1