Getting numbered files with For Each and how to get it in order instead of by the first character

Basically the files I have goes like “1.xlsx”, “2.xlsx”…“100.xlsx” etc, but the loop is only going by the first number in the name so it goes 1-10-100 then 2-20 etc. How to make it so it goes in order?
I’m using Directory.GetFiles(directory,"*.xlsx") to assign the files.

@daqc - Say if the files created in order (one after another)…we can use create time to read it in order…

Directory.GetFiles("YourFolderName","*.xlsx").OrderBy(Function(d) New FileInfo(d).CreationTime).toarray

PLease try and let me know.

1 Like

Cannot assign from type 'System.Linq.|OrderedEnumerable`1[System.String]'to type ‘System.String’ in Assign activity ‘Assign’.

This method could work with what I have now but also let’s say the files will be named in random regardless of the time created what do i do then? Just for future reference, Thanks.

What is your For each Variable type…it should be string…Please check below…

Let me think on this scenario.

1 Like

For Each is String in the TypeArgument

Let me think on this scenario

Thank you very much!

I just updated my code above. Please add .toarray in the end…

1 Like

Yep that worked, thanks! I’ll try the method on my folder with the 100’s of files. But I’m also curious about the other solutions.

Hi @daqc

Try this
Sequential File Access.xaml (8.2 KB)

1 Like

Here you go…

Directory.GetFiles("YourFolderName","*.pdf").OrderBy(Function(d) cint(path.GetFileNameWithoutExtension(d))).toarray

Source: Assign

Message: Conversion from string “test_voice” to type ‘Integer’ is not valid.

Exception Type: System.InvalidCastException

Directory.GetFiles(“YourFolderName”,"*.pdf").OrderBy(Function(d) cint(path.GetFileNameWithoutExtension(d))).toarray

This one is perfect. I think I’ll use this method. Thanks for the inputs and help!

1 Like

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