How to sort files based on different methods in UiPath
Tried sorting files from a folder and finding it difficult to do that?
This article will help you to achieve this.
We can sort files from a folder in two different orders:
- Ascending
- Descending
There are also so many methods by which you can sort files accordingly.
- CreationTime
- CreatedDate
- LastWriteTime
- LastModifiedDate
- LastAccessTime
- LastAccessedDate
In this example, we are going to see how to sort files by using CreationTime.
CreationTime:
This method returns creation date of file as FileTime.
If the file system doesn’t store the date of creating a file, then the method will return the last modified date.
Let’s jump into UiPath Now.
Step1: We need to get the files from a folder.
Now in filepaths it stores all the file paths of different files in that particular folder.
Step2: Now we have all the files and time to write the sorting function to sort files.
The syntax looks like below:
filepaths.OrderByDescending(Function(d) New FileInfo(d).CreationTime)
In the above syntax :
filepaths is a array of string where we stored all our file paths from a folder.
OrderByDescending – It is sort files in Descending order.
CreationTime – It will sort files based on the creation time of each file in a folder.
If you want to sort this in ascending order then use the below syntax:
filepaths.OrderByDescending(Function(d) New FileInfo(d).CreationTime)
OrderByAscending – It will sort the files in Ascending order.
If you want to get each file in that folder after sorting files then we need to use for each.
As mentioned in the above syntax that exact formula is used here for each.
Now, you will get each item in that sorted files file paths.
In this example we have seen how to sort files based on CreationTime.
But, what if you want to sort files based on LastWriteTime.
Just change the syntax as below:
filepaths.OrderByDescending(Function(d) New FileInfo(d).LastWriteTime)
You can notice the change in the syntax where we added LastWriteTime.
If you want to sort files in UiPath based on any other method you can change the syntax as above.
You always describe basics from. NET Framework. Has nothing to do with rpa. See no reason for these post becausr microsoft docs are very good
Hi Rpa, Microsoft docs are good but there you didn’t get how to implement that in UiPath. That will be the added value for the readers who are learning UiPath.As per my knowledge, UiPath is based on .Net Framework, isn’t it?