Click here to Skip to main content
15,888,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
-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.


Python
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.
Posted
Comments
Richard MacCutchan 1-Apr-21 6:08am    
"Basically I need help on this one."
And are we expected to guess what sort of help?
Muvunyi Yahya 1-Apr-21 6:11am    
help on the python script above.
Richard MacCutchan 1-Apr-21 6:16am    
If you want help then please explain in detail what the problem is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900