[英]I want to add all the names of the files in a specific folder to a list
I want to add the names of all the files in a specific folder to a list how can i do that?我想将特定文件夹中所有文件的名称添加到列表中,我该怎么做? the pathway is from dropbox -> a folder called 'UMM' -> a folder called '2018' could someone help me with the code on this.
路径来自 Dropbox -> 一个名为“UMM”的文件夹 -> 一个名为“2018”的文件夹,有人可以帮我编写代码。 I have tried using os.walk() but it doesn't seem to work
我试过使用 os.walk() 但它似乎不起作用
You can use os.walk and append only names which are in files.您只能使用文件中的 os.walk 和 append 名称。
from os import walk
file_names = list()
path = 'path/of/folder'
for root, dirc, files in walk(path):
for FileName in files:
file_names.append(FileName)
print(file_names)
This will append all the files name from all the directories and sub-directories of the specified path.这将 append 指定路径的所有目录和子目录中的所有文件名。
this will create a list of the files in a folder这将创建一个文件夹中的文件列表
from os import listdir
# the path
path = ''
fileList = listdir(path)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.