Reputation: 17
I have nearly 10k excel files in a folder and I have a python list of filenames of nearly 8k. I want to extract the files from that folder that are present in the list, and then keep that files in another folder. I have looked at these answers but none explains my issue:
Any suggestions on how I can do that?
Upvotes: 0
Views: 870
Reputation: 438
You can use this following python script, assuming you are using Linux or mac or if you are using windows us modify the mv command.
import os
def filter_data(list_of_files):
path="/absolute_path_to_directory_to_be_searched"
path_to_be_moved="/ablosute_path_to_file_to_be_moved"
for file in os.listdir(path):
if file in list_of_files:
os.system("mv "+path+file+" "+path_to_be_moved)
if __name__ == "__main__":
filter_data(list)
Upvotes: 1