从IDLE运行时,Python脚本可以看到Y:/ Drive,而不是命令行

时间:2015-02-23 12:08:23

标签: python path server

我有一个python脚本,可以通过搜索文件夹并提取文件列表来构建文件。当我在IDLE中打开并运行它时,此文件运行正常并按预期工作,但如果我在命令行窗口中运行脚本时出现此错误:

C:\Windows\system32>python "C:\Users\ntreanor\Documents\RV Scripts\Server RV Sequence.py"
Traceback (most recent call last):
  File "C:\Users\ntreanor\Documents\RV Scripts\Server RV Sequence.py", line 69,
in <module>
    for foldername in os.listdir(pngFolders):
WindowsError: [Error 3] The system cannot find the path specified:
    'Y:/20_temp_script_testing/pr126 movs\\04_comp_pngs/*.*'

如果不明显,那么路径确实存在。它不仅适用于IDLE,而且我经过双重检查,路径肯定存在。

我还尝试使用作为守护程序运行的脚本创建文件夹,并获得类似的结果

Traceback (most recent call last):
  File "D:\shotgun\shotgunEventDaemon.py", line 888, in process
    self._callback(self._shotgun, self._logger, event, self._args)
  File "D:\shotgun\plugins\CreateAssetFolders.py", line 72, in createAssetFolders
    os.makedirs(folder)
  File "D:\Python27\Lib\os.py", line 150, in makedirs
    makedirs(head, mode)
  File "D:\Python27\Lib\os.py", line 150, in makedirs
    makedirs(head, mode)
  File "D:\Python27\Lib\os.py", line 150, in makedirs
    makedirs(head, mode)
  File "D:\Python27\Lib\os.py", line 157, in makedirs
    mkdir(name, mode)
WindowsError: [Error 3] The system cannot find the path specified: 'Y:/'

这是脚本在此之前记录为文件夹的内容:

Making folder:
Y:/07_design/04_environmental_elements\eec005-08_insect_ladybird_red_7_spots_wide

(之所以说它是Y而不是整个路径是它试图让每个文件夹都回来,直到它不能再回到那里并且抛出异常时)

命令行窗口的环境变量是否会以某种方式影响应该将脚本指向正确位置的驱动器映射?

2 个答案:

答案 0 :(得分:3)

问题可能是因为IDLE和您的命令行以不同级别的权限运行。映射的网络驱动器不会自动可用于所有用户上下文。这个here有一个超级用户问题,很多other资源都涵盖了此主题。简而言之,映射的网络驱动器仅适用于在映射所在级别运行的程序。

如果您已通过Windows UI映射网络驱动器,那么它将映射为未提升的程序。但是,如果它与net use映射,那么它取决于映射时命令提示符的级别!

禁用UAC也会影响更改此行为,因为将使用提升(或不提取)命令提示符,这可以解释为什么某些PC显示不同的行为。

答案 1 :(得分:-1)

我认为您的问题是您正在尝试打开*文件,这当然不存在。 open(path)将path作为文字字符串,并且无论如何都不会将其翻译,因此它希望该值是有效的文件名。您应该更改代码以获取目录而不是文件,然后遍历该目录。

相关问题