Each Loop same name file

Hi,

I have a path file xml and read each loop it
s_path = Directory.GetFiles(in_ParrentFolder+“E-INV”,“*.xml”)

How can loop by the same name SSC-2023-392 (1,2) and next SSC-2023-393 (1,2)
SSC-2023-392-PHILIPPINES-1.xml
SSC-2023-392-PHILIPPINES-2.xml
SSC-2023-393-INDO-1.xml
SSC-2023-393-INDO-2.xml

Thank you for your reply and have a nice day!

@anh.nguyen

Please try this

Directory.GetFiles(in_ParrentFolder+"E-INV","*.xml").OrderBy(function(x) Path.GetFileNameWithoutExtension(x))

Cheers

1 Like

Hi @anh.nguyen

Give a try with the following
in the assing that you are retrieving the files list, put like this

Directory.GetFiles(in_ParrentFolder+"E-INV","*.xml").OrderBy(Function(f) Path.GetFileName(f)).ToArray()

Regards!

1 Like

Hi @anh.nguyen

Hope it helps!!

1 Like

Hi @Anil_G

if i use it directly in the loop, it read all XML file

Hi @fernando_zuluaga

Thank you but it still loops all file XML. I want I just loop the same name SSC-2023-392 (1,2) and the next SSC-2023-393 (1,2)

@anh.nguyen

The ask was the same right…like you should get all files but in order the first and second?

if not please let me know more details

cheers

Yes, I mean want to read files (by rule 12 left character) in the folder no duplicate

My folder has files:
SSC-2023-392-PHILIPPINES-1.xml
SSC-2023-392-PHILIPPINES-2.xml
SSC-2023-393-INDO-1.xml
SSC-2023-393-INDO-2.xml

Want:
SSC-2023-392
SSC-2023-393

@anh.nguyen

So is it like you want to read in groups?

or you can use Directory.GetFiles(in_ParrentFolder+"E-INV","SSC-2023-392*.xml")

cheers

Hi @anh.nguyen

If you want to take the file names in the above file names.
Use the regex expressions.
image

Hope it helps!!

1 Like

Just by rule 12 char, SSC-year-xxx. Not exactly SSC-xxxx-xxx
Yes read in a group, how can read the folder by group file name?

@anh.nguyen

Then first get the group of files and then group by and then loop through and get each set

  1. Directory.GetFiles(in_ParrentFolder+"E-INV","*.xml").GroupBy(function(x) Path.GetFileNameWithoutExtension(x).SubString(0,12)).Select(function(x) Path.GetFileNameWithoutExtension(x.First).SubString(0,12)) use for loop on this
  2. inside loop use Directory.GetFiles(in_ParrentFolder+"E-INV",currentItem + "*.xml")

now you will get each group of files for each outer iteration

cheers

1 Like

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