Current user path on windows /one drive

I am starting to work with relative path. I have a file with the address C:\Users\betol\Downloads\Test.xlsx. I need to move it to another folder. However, I have achieved it with absolute path, putting the username “betol”, however I need the username not to be required.

When I am creating a folder using system.Environment.UserName I get the following error
Create Folder: Access to the path ‘C:\Users\USER\OneDrive\Desktop\2023-06-11’ is denied.

The assign for the variable path is “C:\Users"+system.Environment.UserName+”\OneDrive\Desktop"+Datetime.today.ToString(“yyyy-MM-dd”). How could it work in the case of folders that are with OneDrive?

Hi,

The above expression seems lack backslash after Desktop. Can you try the following?

"C:\Users"+system.Environment.UserName+"\OneDrive\Desktop\"+Datetime.today.ToString("yyyy-MM-dd")

OR System.IO.Path.Combine may be better.

System.IO.Path.Combine("C:\Users",System.Environment.UserName,"OneDrive\Desktop",Datetime.today.ToString("yyyy-MM-dd"))

Regards,