[英]Grabbing first file from each directory using os.walk
I am using the following code to extract all files (with same type) in all subdirectories in parent folder.我正在使用以下代码提取父文件夹中所有子目录中的所有文件(具有相同类型)。
dcm_files = []
for root, dirs, files in os.walk(path):
for names in files:
if names.endswith(".dcm"):
dcm_files.append(os.path.join(root, names))
How do I only get the first file from each subdirectories in parent folder ?如何只从父文件夹中的每个子目录中获取第一个文件?
files
files
files[0]
files[0]
的第一个文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.