Skip to content

Latest commit

 

History

History
15 lines (15 loc) · 502 Bytes

文件目录扫描.md

File metadata and controls

15 lines (15 loc) · 502 Bytes

文件目录扫描

扫描目录下所有文件,递归,但是文件数量多的情况下比较耗时:

all_files_list = []  
for root, dirs, files in os.walk(root_dir):  
    for file in files:  
        all_files_list.append(os.path.join(root, file))  

高效率扫描,只针对单目录结构,不递归:

pkg_file_list = []  
all_file_generator = os.scandir(root_dir)  
for p in all_file_generator:  
    pkg_file_list.append(p.path)