I am using the Microsoft Office 365 activities (Read Range, Read Cell, Get Sheets) in UiPath to read an Excel file from OneDrive. However, the file I want to read is not always at index 0 — its position in the list keeps changing every time. How can I consistently select the specific file I want, regardless of its index?
I hope you are using integration service to access files from OneDrive.
Use a URL (File Share URL) as input for Read Range activity.
When you are using Read Range you can directly pass the URL of the file or you can access by entering the id as well.
or there is one more option instead of these both, first use Get File or Folder activity and save the output in variable and pass that variable in Read Range activity
for more refernce, go throw below documentation of Read range activity and Get File or Folder activity
Activities - Read Range
Activities - Get File/Folder
Happy Automation!!
Actually not i am using classic activities not integration service
I can’t do that because when i am getting the files into desired folder the format changes and due to this i have to change whole code of mapping the data
Does files have any specific naming convention or something that to identify the file ?
You can also get file like, once you get list of files just sort it by Name, or uploaded date time to get top file.
If you can’t use Get file activity, then you should go with Read range there you need to provide the URL of the file or ID.
Or try with API’s if its possible.
in classic you have get file or folder activity which takes the filename and give the one drive item which can be used further
this way it depends on filename but not the index
cheers
try to use the Get Files activity to get all files, loop through each file with for each, check if the file name matches your target using an If condition, save the matching file path to a variable, and then use that variable.
Happy Automation
Okay but when someone modifies the file in onedrive itself then the instance of file is created and bot reads the files on 3rd index sometime on 5th, and 6th, 7th and so on..
But I want that file on my 0th index
See the file is uploaded on Onedrive of Outlook and many peoples have access to that due to which they modifies the files like they add values, remove values, etc and due to that the files creates an instance and when I am running the bot to run the file then bot picks the files on any index but I want it on 0th index
If you want particularly on 0th index, that can be possible by sorting on modified date or based on your files names itself
Ideally once the file is modified the modified or the latest version is what would be available as the file itself is modified and its not that a new file is created , so what you would get would be the modfied file at the time you access it..thats how sharing works
Unless you upload a file everytime you modify
Cheers
@bhavesh.choubey , you could use Power Automate to copy the file to another folder when a new file is uploaded to the folder.
Instead of using index, identify the file by its name or properties.
Use Find Files and Folders activity with the file name in the search query.
Or use Get Children activity and then filter the output:
targetFile = children.Where(Function(f) f.Name = "YourExcelFileName.xlsx").FirstOrDefault()
Then:
Pass targetFile
to your Read Range / Read Cell activity
Result:
The workflow will always pick the correct file regardless of its position.
Yash Thankyou for your response and It worked
Cheers
Yes you’re right but while reading that file it is not on 0th index