Python Forum
Function not executing each file in folder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function not executing each file in folder
#2
Your problem is that first you do this:
for f in os.listdir(path):
    if f.endswith('.docx'):
        files.append(f)

for i in range(len(files)):
    text = docx2txt.process(files[i])
    text2 = text.replace(":", " ")
    text3 = text2.replace(",", " ")
    text4 = text3.replace("_", " ")
    data = text4.split()
Then later on you do this:
#Sends vet list to string
for j in data:
	vet += j + ", "
Was it your plan for vet to concatenate the results for all the files? That is not what happens. Your program only uses data from the last docx file. You should combine finding, processing and appending into one loop. Like this:
vet = ""
for f in os.listdir(path):
    if f.endswith('.docx'):
        text = docx2txt.process(f)
        text = text.replace(":", " ")
        text = text.replace(",", " ")
        text = text.replace("_", " ")
        data = text.split()
        vet += ", ".join(data)
Reply


Messages In This Thread
RE: Function not executing each file in folder - by deanhystad - Aug-14-2022, 08:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete file with read-only permission, but write permission to parent folder cubei 6 25,268 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 1,450 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Reading a file name fron a folder on my desktop Fiona 4 2,044 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Dynamic File Name to a shared folder with open command in python sjcsvatt 9 9,756 Jan-07-2022, 04:55 PM
Last Post: bowlofred
  Code to check folder and sub folders for new file and alert fioranosnake 2 2,920 Jan-06-2022, 05:03 PM
Last Post: deanhystad
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 6,228 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  How to import file and function in another folder SriRajesh 1 5,291 Dec-18-2021, 08:35 AM
Last Post: Gribouillis
  How to run an exe file in the Scripts folder using py.exe? quazirfan 2 4,079 Sep-08-2021, 01:00 AM
Last Post: quazirfan
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 3,089 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  executing a bash file - revisited ebolisa 7 4,047 Feb-10-2021, 08:05 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020