-I have a python script where a user inputs a path to directory.
-Then the program search all files with extensions "pdf" "docx" "jpg".
-It saves all those files found into a txt file called "foundFile.txt
-it then copies all those files with those extensions into a folder called found_files.
Below is the code.
import os
import shutil
dir = "C:/Users/PacY/PycharmProjects/pdfwordtext/found_files"
shutil.rmtree(dir, ignore_errors=True)
os.makedirs(dir)
foundFile = open("C:/Users/PacY/PycharmProjects/pdfwordtext/foundFile.txt", "w+")
input_path = input(r"Enter path of the directory: ")
extensions = ['.pdf', '.docx', '.jpg']
txt_file = r"C:/Users/PacY/PycharmProjects/pdfwordtext/found_files/foundFile.txt"
f = open(input_path,'r+')
with open(txt_file, "a+") as txt:
for file in os.listdir(input_path):
for extension in extensions:
if file.__contains__(extension):
txt.write(file)
txt.write("\n")
What I have tried:
-I have created the txt file (foundFile.txt)
-The directory to get all those files.
-Getting all those file names with those extensions.
-Basically I need help on this one.