用python读取目录及其子目录的内容
我有一个包含10个子目录的目录用python读取目录及其子目录的内容,python,list,directory,subdirectory,Python,List,Directory,Subdirectory,我有一个包含10个子目录的目录path/to/dir。所有子目录中都有文件。我想将每个子目录中的这些文件附加到一个唯一的列表中。 我该怎么做 import glob path = '\\path\\to\\dir\\' files = [f for f in glob.glob(path + "**/*", recursive=True)]
path/to/dir
。所有子目录中都有文件。我想将每个子目录中的这些文件附加到一个唯一的列表中。
我该怎么做
import glob
path = '\\path\\to\\dir\\'
files = [f for f in glob.glob(path + "**/*", recursive=True)]