比较具有不同扩展名的单独文件夹中的两个不同文件,并使用 pywinauto 打开一个文件

Comparing two different files from Separate Folders with different extensions and opening one with pywinauto

我正在尝试比较来自具有不同扩展名的不同文件夹中的两个不同文件,然后尝试使用 pywinauto 打开一个文件。该应用程序会打开,但是我提到的扩展名的文件不会打开。

我尝试遍历多个文件但没有用,我给了一个特定的文件名。只是应用程序打开。

下面是我试过的代码。

from pywinauto.application import Application
import os
app = Application(backend="uia").start('C:\Program Files (x86)\Datawatch Monarch 14\DWMonarch.exe')
#app.Dialog.print_control_identifiers()
path = (r'C:\Check\Monarch\ICRDIS.dprj')
path2 = (r'C:\DOLV\ICRDIS.txt')

name1 = path.rsplit('.', 1)[0] 
name2 = path2.rsplit('.', 1)[0]

#for name1 in path:
 #   for name2 in path2:
if name1 == name2:
    try:
        print(name1)
        app.Dialog.child_window(title="Open", auto_id="Open", control_type="SplitButton")
        app.Dialog.child_window(title="File", auto_id="PART_ApplicationButton", control_type="Button")
        app.Dialog.Menu.Open(path.dprj)
                #app.Dialog.Open('name1.dprj')
    except:
        print("No File Name Matches")

这是带有开放选项的 Monarch 的控件标识符:

 Menu - 'Ribbon'    (L-4, T30, R1924, B171)
   | ['RibbonMenu', 'Ribbon', 'Menu']
   | child_window(title="Ribbon", auto_id="MainRibbon", control_type="MenuBar")
   |    | 
   |    | Separator - ''    (L26, T1, R29, B21)
   |    | ['17', 'Separator3']
   |    | child_window(auto_id="beforeSeparator", control_type="Separator")
   |    | 
   |    | SplitButton - 'Open'    (L31, T-3, R72, B25)
   |    | ['OpenSplitButton', 'Open', 'SplitButton', 'SplitButton0', 'SplitButton1']
   |    | child_window(title="Open", auto_id="Open", control_type="SplitButton")

几个问题我如何使用提到的控件打开特定应用程序并遍历多个文件。

我做错了什么导致它不起作用?请提出建议。

此致, 仁.

感谢 Vasily 的建议。下面是我的全部代码。

import os
import shutil
from pywinauto.application import Application
from pywinauto import Desktop
import pandas as pd
from datetime import date
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from os import walk
from os.path import splitext
import subprocess
import time
from time import sleep

monarch_files = r'C:\Health Check\Support Monarch Project'
monarchPath = 'C:\Program Files (x86)\Datawatch Monarch 14\DWMonarch.exe'
fileformat ='xprj'
fileformat2='dprj'

rundate = date.today()

job_name = pd.read_excel(r'C:\Check\Job Name.xlsx',
                     sheet_name = 'JobName',
                     header = 0
                     )
for index , row in job_name.iterrows():
    jobname = row['JobName']
    filename=row['ReportName']

    for file_name in dolv_files:
        fname=file_name.rsplit('.', 1)[0]
        if fname==filename:
            print(jobname)
            file_open = os.path.join(monarch_files,jobname + "." + fileformat)
            file_open1 = os.path.join(monarch_files,jobname + "." + fileformat2)
            if os.path.exists(file_open):
                subprocess.Popen([monarchPath,file_open])
                sleep(10)
                dlg=Desktop(backend='uia').window(title_re='Datawatch Monarch *')
                sleep(5)
                try:
                    dlg.Resolve_Missing_Model_Files.OK.invoke()
                    dlg=Desktop(backend='uia').window(title_re='Datawatch Monarch *')
                    dlg.Export.invoke()
                    dlg.Select_All_Exports.invoke()
                    dlg.Run_Exports.invoke()
                    sleep(5)
                    dlg.close()
                    try:
                        dlg.No.invoke()
                    except:
                           print('e')
                except:
                    dlg.Export.invoke()
                    dlg.Select_All_Exports.invoke()
                    dlg.Run_Exports.invoke()
                    sleep(5)
                    dlg.close()
                    try:
                        dlg.No.invoke()
                    except:
                            print('e')
            elif os.path.exists(file_open1):
                    subprocess.Popen([monarchPath,file_open1])
                    dlg=Desktop(backend='uia').window(title_re='Datawatch Monarch *')
                    sleep(5)
                    try:
                        dlg.Resolve_Missing_Model_Files.OK.invoke()
                        dlg=Desktop(backend='uia').window(title_re='Datawatch Monarch *')
                        dlg.Export.invoke()
                        dlg.Select_All_Exports.invoke()
                        dlg.Run_Exports.invoke()
                        sleep(5)
                        dlg.close()
                        try:
                            dlg.No.invoke()
                        except:
                               print('e')
                    except:
                        dlg.Export.invoke()
                        dlg.Select_All_Exports.invoke()
                        dlg.Run_Exports.invoke()
                        sleep(5)
                        dlg.close()
                        try:
                            dlg.No.invoke()
                        except:
                            print('e')                       
            else:
                print("File Not Found")

此致, 仁.