How to get files in the order they are in the folder

Hi,

I have download a few files in a folder, now i want to get the file names into an excel, according to the time they created. The first downloaded name needs to come first.
ex: i have created files in the order of 3,7,2,4,8,9…
Now, in excel , i want to add there names in the same order
3
7
2
4
8
9…

I tried the options showed in the community, they didnt work out for me.

Can anyone help me, TIA

Hi @Santhosh_Hyd

Can you check the below post:

1 Like

@Santhosh_Hyd

Try this:

Directory.GetFiles(“folderPath”).OrderByDescending(Function(x) x.LastWriteTime).ToArray

2 Likes

Hi buddy

Hope these steps could help you resolve this issue buddy
—use a assign activity and mention like this
Out_Filepatharray = Directory.GetFiles(“YourFolderPath”).OrderByDescending(Function(d) New FileInfo(d).CreationTime)

Where Out_Filepatharray is a variable of type String array

—then use excel application scope and pass the file path
— use a for each loop within this scope and pass the variable out_Filepatharray as input and change the type argument of for each loop as string in its property panel
—inside this loop use a write cell activity with sheet name where to write and value as item which is the variable that has the value from out_Filepatharray array variable and put the range as “C”+counter.ToString
Where counter is a variable of type int32 with default value as 2 and I have used Column C here assuming that we need to update the file names in column C, you can change as per your need
— next to this write cell activity and at last in for each loop use a assign activity To increment the value of counter like this
counter = counter + 1

That’s all buddy
Hope this’ you
Kindly try this and let know for any queries or clarification
Cheers @Santhosh_Hyd

3 Likes

Hi @Santhosh_Hyd

Please see the below sample and see if this is what you after, basically it try to read the files in the folder, print file name and creation time in order. So if this is what you after, you can add write file name into the excel in the for each loop.

FilesOrder.zip (12.2 KB)

Cheers

1 Like

Thanks, it worked for me, thanks for the others too

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.