我试图用Python从网络驱动器中提取文件夹名。例如,如果我有一个映射的驱动器U:,我想从路径\emily\hello\example
遍历并获取文件夹“example”中的所有文件夹。在
到目前为止,我一直在努力。在
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)
这会导致许多错误,我在网络上的共享驱动器与本地计算机上的文件夹的语法有问题。在
我想在一个列表中看到它们,这样我就可以逐行阅读并将这个列表与另一个列表进行比较。在
我不需要文件夹中的文件,只需要文件夹中的文件夹名
谢谢~!在
错误消息为C:\Users\212582086\AppData\Local\Continuum\Anaconda3\python.exe“C:/Users/212582086/Desktop/Vendor sort/main” 回溯(最近一次呼叫): 文件“C:/Users/212582086/Desktop/Vendor sort/main”,第6行,英寸 os.chdir公司(方向) FileNotFoundError:[WinError 3]系统找不到指定的路径:'\emily\hello\example\Software Archive'
进程结束,退出代码为1
目前没有回答
相关问题 更多 >
编程相关推荐