0
I have several files like this:
- C:\ByMe\SOLUTIONS\Dictation1\Database\Updates\2017\2017_04\20170405_TR\1_CREATE_TABLE_BMTApprovalGroupExam.sql
- C:\ByMe\SOLUTIONS\Dictation1\Database\Updates\2017\2017_04\20170405_TR\10_CREATE_PROC_BMSPInsertNewApprovalRequest2.sql
- C:\ByMe\SOLUTIONS\Dictation1\Database\Updates\2017\2017_04\20170405_TR\11_CREATE_PROC_BMSPUpdateApprovalRequest2.sql
- C:\ByMe\SOLUTIONS\Dictation1\Database\Updates\2017\2017_04\20170405_TR\2_CREATE_PROC_BMSPInsertNewApprovalGroupExam.sql
I need to sort the files like this in C#:
- C:\ByMe\SOLUTIONS\Dictation1\Database\Updates\2017\2017_04\20170405_TR\1_CREATE_TABLE_BMTApprovalGroupExam.sql
- C:\ByMe\SOLUTIONS\Dictation1\Database\Updates\2017\2017_04\20170405_TR\2_CREATE_PROC_BMSPInsertNewApprovalGroupExam.sql
- C:\ByMe\SOLUTIONS\Dictation1\Database\Updates\2017\2017_04\20170405_TR\10_CREATE_PROC_BMSPInsertNewApprovalRequest2.sql
- C:\ByMe\SOLUTIONS\Dictation1\Database\Updates\2017\2017_04\20170405_TR\11_CREATE_PROC_BMSPUpdateApprovalRequest2.sql
I did so:
string[] sqlFiles = Directory.GetFiles(path, "*.sql", SearchOption.TopDirectoryOnly);
foreach (string file in sqlFiles.OrderBy(file => file)) { }
But it’s not working. It’s performing for the first step I’ve taken.
Is it certain that the first thing in the file name will be a number? And will always have an underline after?
– Jéf Bueno
Yes it is right. The first thing in the name will be the number.
– Ana Carvalho
@Anacarvalho if the number is repeated, the lexicographic order must be the tiebreaker criterion?
– mercador
if the filename were 01, 02, 10 and 11 would facilitate sorting =]
– Rovann Linhalis
It was, but as it is for my work, it is already defined from the beginning.
– Ana Carvalho
Good morning Ana. Please could you [Edit] your question and add the information about the full file path? This totally changes the content of the answers that might arise.
– Randrade
I corrected the question
– Ana Carvalho