Hi all,
I have a folder which consists of pdf files with naming convension as ‘’'Document-{Counter}". I have total of 30 pdf files. I want all the pdf file names in an array in ascending order.like
{//User/Document-1,//User/Document-2,//User/Document-3,… }
when sorting i am getting the output as
{//User/Document-1,//User/Document-10,//User/Document-11,… }. it is sorting as number series.
Can anyone help me out with this?
Naga_Abhishek_Reddy_Chepp:
{//User/Document-1,//User/Document-10,//User/Document-11,… }
Hi @Naga_Abhishek_Reddy_Chepp ,
Could you maybe specify the full proper format that the file names are using ?
We could Extract the Number and order it based on the number, But we would need to know it’s position/ full pattern of the file name.
{Abhi-1.pdf,Abhi-2.pdf,Aish-1.pdf,Aish-2.pdf}
postwick
(Paul Ostwick)
November 10, 2022, 6:12pm
4
CInt(Split(“abhi-1.pdf”.Replace(“.pdf”,“”),“-”)(1)) will give you the digit as an actual numeric value.
Naga_Abhishek_Reddy_Chepp:
{Abhi-1.pdf,Abhi-2.pdf,Aish-1.pdf,Aish-2.pdf}
@Naga_Abhishek_Reddy_Chepp ,
Check with the below Expression :
filesArray.Orderby(Function(x)CInt(Split(Path.GetFileNameWithoutExtension(x),"-")(1))).ToArray
Here, filesArray
is the array of string containing the file paths
Yoichi
(Yoichi)
November 10, 2022, 11:34pm
6
Hi,
If your input is
Abhi-1.pdf
Abhi-10.pdf
Abhi-2.pdf
Aish-1.pdf
Aish-10.pdf
Aish-2.pdf
and expected output is
Abhi-1.pdf
Abhi-2.pdf
Abhi-10.pdf
Aish-1.pdf
Aish-2.pdf
Aish-10.pdf
the following expression will work
arrStr = arrStr.OrderBy(Function(f) Int32.Parse(System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(f),"\d+$").Value)).GroupBy(Function(f) System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(f),".*\D(?=\d+$)").Value).SelectMany(Function(g) g).ToArray
Sample20221111-1.zip (2.4 KB)
Regards,