I am trying to save files to users desktop, or even their Documents folder but several people have OneDrive enabled and are syncing either one or both of them which changes their path completely.
Any code I run, whether it is Python or VBA, while it doesn't seem to explicitly fail, doesn't work either. The code runs and a file is supposedly created but never actually appears and becomes "lost". From what I have read it is likely due to OneDrive catching the file during its creation and trying to do something with it but fails.
Would any happen to know a way to bypass OneDrive, or work with it in the event it is enabled? I remember reading somewhere that I likely have to work with its API.
For the record, this is what I was trying to use to check for its use:
Any code I run, whether it is Python or VBA, while it doesn't seem to explicitly fail, doesn't work either. The code runs and a file is supposedly created but never actually appears and becomes "lost". From what I have read it is likely due to OneDrive catching the file during its creation and trying to do something with it but fails.
Would any happen to know a way to bypass OneDrive, or work with it in the event it is enabled? I remember reading somewhere that I likely have to work with its API.
For the record, this is what I was trying to use to check for its use:
Python:
is_onedrive_in_use = False
try:
# Open OneDrive registry key
with winreg.OpenKeyEx(
winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\OneDrive\Settings',
0,
winreg.KEY_READ
) as key:
# Get value of the UserFolder key
user_folder_value = winreg.QueryValueEx(key, 'UserFolder')[0]
# Check if it being redirected to OneDrive
if user_folder_value != os.path.expanduser('~\\Desktop'):
is_onedrive_in_use = True
except Exception as e:
print(e)
target_desktop_path = os.path.expanduser('~\\Desktop')
if is_onedrive_in_use:
target_desktop_path = user_folder_value
return target_desktop_path