My python script executes a call to os.listdir(path)
where the path contains folders that I need to work on one by one. 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)
?
ignored = {"folder_one", "folder_two", "folder_three"}
folders = [x for x in os.listdir(path) if x not in ignored]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With