sort files

Sashikala

New member
Joined
Dec 15, 2011
Messages
4
Programming Experience
5-10
There are word files in subfolders (Batch_1, Batch_2,Batch_3 etc). The Batch1 is having ch002.doc,ch005.doc files. The Batch 2 is having ch001.doc , ch004.doc files. Let me know the possiblities of
sorting the files in order from different subfolders. I request this to merge the word files in order.

thanks,
Sashi
 
I don't think that you should need to do any sorting at all. GetFiles should return the file paths in alphabetical order. If it doesn't then Array.Sort should do it for you.
 
I don't think that you should need to do any sorting at all. GetFiles should return the file paths in alphabetical order. If it doesn't then Array.Sort should do it for you.

Files list:

D:\test\Batch_1\ch002.doc
D:\test\Batch_1\ch004.doc
D:\test\Batch_2\ch001.doc
D:\test\Batch_2\ch003.doc

The output should be like this:

D:\test\Batch_2\ch001.doc
D:\test\Batch_1\ch002.doc
D:\test\Batch_2\ch003.doc
D:\test\Batch_1\ch004.doc

Array.sort did not sort the files as well as getFiles method. Is there any other method..

thanks,
Sashi
 
Ah, so you want to sort by file name irrespective of folder. You didn't really explain that clearly. In that case, you could do this:
Dim files As New List(Of FileInfo)

files.AddRange(New DirectoryInfo(folderPath1).GetFiles())
files.AddRange(New DirectoryInfo(folderPath2).GetFiles())

files.Sort(Function(fi1, fi2) fi1.Name.CompareTo(fi2.Name))
 
Back
Top