Files reading in seq order

Hi,I am readig the files and then writing into the template,
Here if you see jul month file is on second number.
So first I want to read the Jul then Aug. means months orderwise, Please suggest,
image
@Palaniyappan @Lahiru.Fernando @lakshman

1 Like

Fine
We can try with this expression
arr_filepath = Directory.GetFiles(“yourfolderpath”,”*.xlsx”).OrderBy(function(d) New FileInfo(d).CreationTime)

Cheers @balkishan

2 Likes

Hey Thanks for the response Palani.

1 Like

Sorry that was a typo mistake
Remove FirstOrDrfault in the above expression and try once
Cheers @balkishan

We can try with this expression
arr_filepath = Directory.GetFiles(“yourfolderpath”,”*.xlsx”).OrderBy(function(d) New FileInfo(d).CreationTime)

Bro, where is FirstOrDefault bro in the above expression???

1 Like

Yah I changed now
Kindly use that expression (in the above comment)

Cheers @balkishan

1 Like

still showing error.
image
image

1 Like

Fine add .ToArray() atleast pls

Cheers @balkishan

1 Like

It’s reading Aug first bro, I want to read July then Aug, means in monthwise…

see here are two files, I want to write first July then Aug…

image

1 Like

Hi @balkishan

This is another way to solve it…

  • Create a String array that contains all the months as below
    {“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”}

  • Now read the files in the folder to another array
    Directory.GetFiles(FilePath)

  • Use a For Each loop to loop through the Months array

  • Within the loop, use another For Each to loop through the files

  • Within the second loop, Use an IF condition to check whether the month name is a part of each file. If the file name contains the month selected in the current month iteration, process it, else check the next file…

  • This will make sure you process each file in the month order. Why I used this approach is, your file can contain different other values in front of the month indicator. So, we are referring to a month array to maintain the order of the execution :slight_smile:

Kindly try with order by descending
Like this
arr_filepath = Directory.GetFiles(“yourfolderpath”,”*.xlsx”).OrderByDescending(function(d) New FileInfo(d).CreationTime)

Cheers @balkishan

1 Like

I used the above query, But it executing the Aug file first.

I want to execute First Jul then Aug…

You want to give me any If condition inside the Loop???

Hmmm
I have a small doubt here
Earlier we used just orderby
And followed by that we used orderbydescending
Both gives the same aug as first file
How
Are we editing that file along the process…
Fine
We can use of condition yah of course that would work
Cheers @balkishan

1 Like

which condition I have to sue bro,

see bro I have multiple folder in each folder I have two files in this naming convention image

Now I want first Read the Jul file then Aug…from each of the folder…means Months orderwise. Hope you understand.

1 Like

Were they created month wise
What is their creation time if possible can I have their screenshot
Cheers @balkishan

1 Like

Yes. these are reports and I have to feed the data month wise…bro

Like first Jul then Aug…
Ex. Jan data
Feb data
March data

so on…

Naming will be same all the time

1 Like

Fine
Here you go a sample xaml
Hope it’s resolved
balki.zip (25.7 KB)

Cheers @balkishan

1 Like

Hi,

The function which you are using to order by Creation time will pick the file first which is created first.
and i believe the Aug file is created earlier then the July one.

As a result, it will pick the August File first.

Hi @Palaniyappan
Same solution @Lahiru.Fernando provided.
Both of the solution is working fine. Thanks a lot Lahiru & Palani!! :slight_smile:

Before closing the topic I have a small query.

As I have multiple folder.
In each folder I have 2 files as I mentioned.

First I am reading all the Folder
Then files…

In the first itiration of the Loop it fetch the folder1 and the file inside it and process it.
In the second time of folder it fetch the same folder1 and process the same two files which has been processed. Can you help.

Looping is fine as I checked.
@Lahiru.Fernando @Palaniyappan