Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Files in Directory based on these rules...

Status
Not open for further replies.

fooobee

Technical User
Nov 13, 2003
33
US
I am trying to work on a sorting algorithm for this structure. Since I am not that well versed in algorithms, I was wondering if there are any guru's here willing to help?

The sort is driven by a string in the file name bounded by the first hyphen from the left, e.g. for the file 06CP02MajDep-ET_pre the sort is driven by the string beginning –ET_

Not every term in the list below will have a file. Some terms may have greater than 1 (and an alpha sort may be used in that case).

-Info_
-TOC_
-AB_
-ES_
-FES
-Intro_
-EtioPath_
-EtioPath-LP
-Epi_
-Epi-LP
-CT_
-CT-LP
-MP_
-MP-LP
-UN_
-UN-LP
-ET_
-ET-LP
-MKT_
-MKT-LP
-TM
-PL_
-Meth_
-BB_
-T0
-T1
-T2
-T3
-T4
-F0
-F1
-F2
All Others

 
Could you explain a little more? When you say "sort", do you mean list? What exactly are you doing here? Sort...and do what?

Also, as this is the VBA forum, could you explain what you are doing with VBA, and what application you are working with?

Gerry
 
I was doing this in VBA. I wrote a function to combine word files from a specified directory. The function automatically combines the files alphabetically from their file names. However, I need to write a sorting function to combine the word files based on the above posted criteria.

I presume we need to put all the filenames into an array and pass that array to a custom sorting function.
 
So you want to list the files you find in order:
all files of form, *-Info_*,
followed by all files of form, *-TOC_*,
etc.
Is that right?

If that is the case, the only way I can see to do it is to get the entire directory into a collection:
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(<folderspec>)
Set fc = f.Files


Then you would have to loop through the collection for each file name filter, in order, outputing those that meet the criterion. I would use inStr:
InStr(string1, string2)
and check that the long returned is >0.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top