简体   繁体   English

忽略os.listdir(path)Python中的一些文件夹

[英]Ignore some folders in os.listdir(path) Python

My python script executes a call to os.listdir(path) where the path contains folders that I need to work on one by one. 我的python脚本执行对os.listdir(path)的调用,其中路径包含我需要逐个处理的文件夹。 There are a few folders that need special treatment and need to be out of the list. 有一些文件夹需要特殊处理,需要不在列表中。

How can I exclude those folders from the list returned by os.listdir(path) ? 如何从os.listdir(path)返回的列表中排除这些文件夹?

ignored = {"folder_one", "folder_two", "folder_three"}
folders = [x for x in os.listdir(path) if x not in ignored]

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

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