I have a folder that has hundreds of files in it. I have a list of files that I know need to be deleted, so I am trying to write code to figure out: which files in this list are in this folder, and which are not.
I am using the os module, and I know how to walk through all of the files in my folder using os.walk
, but what I don't know is how to specify if the file is in my files_list
.
So I want to check if the file name in my files_list
is in "folder" and if it is, then append it to bad_list
, and if it isn't then append it to good_list
. This is what I have so far:
for root, dirs, files in os.walk(my_path):
for file in files:
if file in folder:
badlist.append(file)
else:
good_list.append(file)
My question is, how do I put in the "is in files_list
" part of this? I assume it should go after the if file in folder
part, to say something like "is in files_list
" but I can't figure out exactly how to write that in the code.
I am new to Python, so apologies if this is very simple.