'How to check first if directory exists before typing characters using python type_keys() then pressing send using send_keys?

I am using pywinauto. This is my initial code when I type a specific directory then immediately press send using send_keys

dlg.type_keys(r'start "" "Downloads"', with_spaces=True)
send_keys("{ENTER}")

My problem is what if OneDrive directory is available and it is the directory being used instead of my code above. Sample OneDrive directory goes like this:

dlg.type_keys(r'start "" "OneDrive\Downloads"', with_spaces=True)
send_keys("{ENTER}")

How can I first check if the directory is available or not, before typing in the directory and pressing send? How should I add a checking for the two codes above

UPDATE: I TRIED LIKE THIS BUT IT DOES NOT WORK

if os.path.exists("OneDrive"):
    dlg.type_keys(r'start "" "OneDrive\Downloads"', with_spaces=True)
else:
    dlg.type_keys(r'start "" "Downloads"', with_spaces=True)
send_keys("{ENTER}")

My issue is similar with this one: Python os cannot get path to Desktop on One Drive but it did not get a concrete answer



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source