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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORDER AND LOOP files in dir

Status
Not open for further replies.

sal0003

Programmer
Apr 5, 2010
22
0
0
IT
I have adir c:\miadir\ with this type of files:
aa.mdb
ff.doc
TEST_01-09-2011.TXT
TEST_02-09-2011.TXT
TEST_02-11-2011.TXT
TEST_03-10-2011.TXT
TEST_04-10-2011.TXT
TEST_05-09-2011.TXT
TEST_05-10-2011.TXT
TEST_01-09-2011.TXT
TEST_02-09-2011.TXT
TEST_02-11-2011.TXT
TEST_03-10-2011.TXT
TEST_04-10-2011.TXT
TEST_05-09-2011.TXT
TEST_05-10-2011.TXT
TEST_06-09-2011.TXT
TEST_06-10-2011.TXT
TEST_07-09-2011.TXT
TEST_07-10-2011.TXT
TEST_08-09-2011.TXT
TEST_09-09-2011.TXT
TEST_10-10-2011.TXT
TEST_11-10-2011.TXT
TEST_12-09-2011.TXT
TEST_12-10-2011.TXT
TEST_13-09-2011.TXT
TEST_13-10-2011.TXT
TEST_14-09-2011.TXT
TEST_14-10-2011.TXT
TEST_15-09-2011.TXT
TEST_16-09-2011.TXT
TEST_18-10-2011.TXT
TEST_19-09-2011.TXT
TEST_19-10-2011.TXT
TEST_20-09-2011.TXT
TEST_20-10-2011.TXT
TEST_21-09-2011.TXT
TEST_21-10-2011.TXT
TEST_22-09-2011.TXT
TEST_23-09-2011.TXT
TEST_24-10-2011.TXT
TEST_25-10-2011.TXT
TEST_26-09-2011.TXT
TEST_26-10-2011.TXT
TEST_27-09-2011.TXT
TEST_27-10-2011.TXT
TEST_28-09-2011.TXT
TEST_28-10-2011.TXT
TEST_29-09-2011.TXT
TEST_30-09-2011.TXT
TEST_31-10-2011.TXT

i need to loop in dir only .txt files but before order the txt file by dates possible?
 

Can you just rename the TXT files?

[tt]TEST_31-10-2011.TXT[/tt] to be [tt]TEST_2011-10-31.TXT[/tt]


Have fun.

---- Andy
 
It would be best to have them as Andrzejek says. If not, you won't be able to sort by year. If you do, the simple way to handle your requirement is to use the sort pipe in DOS. You can send the result to a file, too. So: [tt] dir *.txt |sort >myfile.txt[/tt]

An unforeseen consequence of the information revolution has been the exponential propagation of human error.
 
Bob, i cannot rename... the file (all part of my project point on the actuall name of txt file)...
 

Could you tell us in more details what are you trying to accomplish? A little more than just your original question. Why do you need to have the files in that order?

Have fun.

---- Andy
 

Just for kicks and giggles I took your example of your TEST files, drop them into a simple text file (files.txt), placed a combo box (cboFiles) on the Form and set the Sort property of the combo to True (poor or lazy man's sorting way, and I am a lazy guy... :) ) You can use some other way to sort the outcome if you want.
Code:
Dim strTextLine As String
Dim sYYYY As String
Dim sMM As String
Dim sDD As String
Dim i As Integer

cboFiles.Clear

Open App.Path & "\files.txt" For Input As #1
Do While Not EOF(1)
   Line Input #1, strTextLine
   
   sYYYY = Mid(strTextLine, 12, 4) [green]'Pick Year[/green]
   sMM = Mid(strTextLine, 9, 2)    [green]'pick Month[/green]
   sDD = Mid(strTextLine, 6, 2)    [green]'pick Day[/green]
   
   cboFiles.AddItem sYYYY & sMM & sDD & " " & strTextLine
Loop
Close #1

For i = 0 To cboFiles.ListCount - 1
    Debug.Print Split(cboFiles.List(i), " ")(1)
Next i

and you get your files sorted:[tt]
TEST_01-09-2011.TXT
TEST_01-09-2011.TXT
TEST_02-09-2011.TXT
TEST_02-09-2011.TXT
TEST_05-09-2011.TXT
TEST_05-09-2011.TXT
TEST_06-09-2011.TXT
TEST_07-09-2011.TXT
TEST_08-09-2011.TXT
TEST_09-09-2011.TXT
TEST_12-09-2011.TXT
TEST_13-09-2011.TXT
TEST_14-09-2011.TXT
TEST_15-09-2011.TXT
TEST_16-09-2011.TXT
TEST_19-09-2011.TXT
TEST_20-09-2011.TXT
TEST_21-09-2011.TXT
TEST_22-09-2011.TXT
TEST_23-09-2011.TXT
TEST_26-09-2011.TXT
TEST_27-09-2011.TXT
TEST_28-09-2011.TXT
TEST_29-09-2011.TXT
TEST_30-09-2011.TXT
TEST_03-10-2011.TXT
TEST_03-10-2011.TXT
TEST_04-10-2011.TXT
TEST_04-10-2011.TXT
TEST_01-09-2011.TXT
TEST_01-09-2011.TXT
TEST_02-09-2011.TXT
TEST_02-09-2011.TXT
TEST_05-09-2011.TXT
TEST_05-09-2011.TXT
TEST_06-09-2011.TXT
TEST_07-09-2011.TXT
TEST_08-09-2011.TXT
TEST_09-09-2011.TXT
TEST_12-09-2011.TXT
TEST_13-09-2011.TXT
TEST_14-09-2011.TXT
TEST_15-09-2011.TXT
TEST_16-09-2011.TXT
TEST_19-09-2011.TXT
TEST_20-09-2011.TXT
TEST_21-09-2011.TXT
TEST_22-09-2011.TXT
TEST_23-09-2011.TXT
TEST_26-09-2011.TXT
TEST_27-09-2011.TXT
TEST_28-09-2011.TXT
TEST_29-09-2011.TXT
TEST_30-09-2011.TXT
TEST_03-10-2011.TXT
TEST_03-10-2011.TXT
TEST_04-10-2011.TXT
TEST_04-10-2011.TXT
[/tt]


Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top