Windows File Path Location Manipulation

Hi, I am using the Path Exist activity and have the activity working. I however, need to make the code work for any computer, I have figured the username to change according to the pc. However, the file is going to be in a OneDrive and at the moment the file path has the unique onedrive account, is there a way to indicate one drive in general so that any pc with whatever account in one drive is there, its like in selector you put an asterisk. The 00000 after the One Drive is going to change according to the pc, is there a way to make it so it works on any one drive account?

image

@FilipeChiou

I think you need to keep an mapping sheet according to the username.

1 Like

Hi @FilipeChiou

Perhaps using an Assign-Activity works for you, where you assign i.e.
str_Username= System.Environment.UserName

Similar cases could help you resolve your issue. However, depending on how OneDrive is set up on each device, it’s not 100 % guaranteed that you’ll find the right target/destination with this method.

You may want to verify with i.e. the “Path Exists” (File exists is included there) to apply some Exception Handling.

Best regards
Roman

1 Like

You could use GetDirectories() to get the OneDrive folder if it always follow the pattern “OneDrive - *”.

onedrivefolder = Directory.GetDirectories("C:\Users\" + username, "OneDrive - *").First
fullpath = Path.Combine(onedrivefolder, "filename", "document.xlsx")
1 Like

You can use environment variable to get that.

Example Path: C:\Users\jobinjoy\OneDrive - company.com\Documents\UiPath

path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),“UiPath”)

1 Like

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)

2 Likes

Hi all, I tried your suggestions and unfortunately they didnt work. Maybe I didnt phrase the questions correctly. But I would like to find a way to assign whatever the One Drive Account is called. Is there a way to access the name. E.g the red line

image

Hi @FilipeChiou ,
You can use the below code to get the path to the my documents folder from that you can extract the one drive portion using string operations.

Assign strMyDocs=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Assign strOneDrive= Split(strMyDocs,"")(3)

Cheers

1 Like