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,
@Palaniyappan @Lahiru.Fernando @lakshman
Fine
We can try with this expression
arr_filepath = Directory.GetFiles(“yourfolderpath”,”*.xlsx”).OrderBy(function(d) New FileInfo(d).CreationTime)
Cheers @balkishan
Hey Thanks for the response Palani.
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???
still showing error.
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…
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
Kindly try with order by descending
Like this
arr_filepath = Directory.GetFiles(“yourfolderpath”,”*.xlsx”).OrderByDescending(function(d) New FileInfo(d).CreationTime)
Cheers @balkishan
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
which condition I have to sue bro,
see bro I have multiple folder in each folder I have two files in this naming convention
Now I want first Read the Jul file then Aug…from each of the folder…means Months orderwise. Hope you understand.
Were they created month wise
What is their creation time if possible can I have their screenshot
Cheers @balkishan
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
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!!
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