2

I want user to enter a path and then my program should open all txt files in that folder. i wrote my code like this and i have no idea how to tell it to open all the txt files. thanks for your help.

from pywinauto import application
import psutil
import os


def Open_file():
    app = application.Application()

    path = input("path : ")
    DOCs = os.listdir(path)

    if len(DOCs) > 0:
        for i in os.listdir(path):
            if i.endswith('.txt'):
                app.start("notepad.exe")
                app.Notepad.menu_select("File->Open")


Open_file()

i wrote it like this. it opens notepad but i can't open all the txt files in that folder.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
gmh
  • 23
  • 4

1 Answers1

0
def Open_file():
    app = application.Application()
    path = input("path : ")
    DOCs = os.listdir(path)
    absolutePath = os.getcwd()+"/"+path
    if len(DOCs) > 0:
        for i in os.listdir(path):
            if i.endswith('.txt'):
                app.start(f"notepad.exe {absolutePath}/{i}")