我尝试访问的路径是../Pictures/NewYork
self.path = "../Pictures/NewYork"
self.files = os.listdir(self.path )
我收到一条错误消息,说
The system cannot find the path specified: '../Pictures/NewYork/*.*'
有没有更好的方法升级?
答案 0 :(得分:0)
只是一个疯狂的客人......你想从py文件所在的地方上去?
os.listdir("../Pictures/NewYork")
将与当前工作目录相关,可能是任何内容。
如果我猜对了,你想要这个:
this_dir = os.path.dirname(__file__)
new_york_dir = os.path.join(this_dir, '..', 'Pictures', 'NewYork')
files = os.path.listdir(new_york_dir)