os.listdir('。')列表也包含来自/ father目录的文件

时间:2016-02-07 18:08:35

标签: python

在运行我的puyton脚本时,我遇到了一个奇怪的问题 -

这是有问题的一行:

(Pdb) n
> c:\py\rename\change_file_ctime_full.py(28)mainProc()
-> filesInScriptDir = [f for f in os.listdir('.') if (os.path.isfile(f) and str(os.path.basename(str(f))).split('.', 1)[1].upper() != 'PY')]

在这里,我正在扫描当前目录os.listdir('.'))并列出扩展名不是os.path.isfile(f)的每个文件(.py条件)(第2条长) condotion)。

在检查代码时,我看到新列表在逻辑上等于或小于dir内容,实际上有更多文件而不是目录本身:

(Pdb) os.listdir('.')
['12547238_163653840672244_2088444628_n.jpg', 'change_file_ctime_full.py']
(Pdb) filesInScriptDir
['12547238_163653840672244_2088444628_n.jpg', 'f.txt', 'Google API notes.txt', 'secret_new.json', 'YoutubeBot_client_secrets.json']

该列表实际上包含上述目录中的文件(其中当前目录列为文件夹)。 怎么解释这个?

感谢。

BTW - 我在IPython窗口中设置了正确的目录,我正在执行该脚本。为了确保我只按名称(而不是完整路径)执行脚本:

In [64]: execfile('change_file_ctime_full.py')

0 个答案:

没有答案
相关问题