简体   繁体   English

python中的os.listdir()不会显示目录的所有文件。 它跳过了几个

[英]os.listdir() in python doesn't show all the files of directory. It skipped few of them

I tried to open all the files(csv) of a directory and append a column to new dataframe. 我试图打开目录的所有文件(csv),并将一列添加到新的数据框。 But, os.listdir() doesn't show all files of the directory.. skipped few of them 但是,os.listdir()不会显示目录的所有文件。

import os
path1=r'D:\data files'
filenames=os.listdir(path1)
print(filenames)

You could try doing it with system commands 您可以尝试使用系统命令进行操作

files = os.system("cd /data\ files && ls")

You might have to add in the path of the directory but this should to the trick. 您可能必须添加目录的路径,但这应该有用。 Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM