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

Find Date

Status
Not open for further replies.

deeneyp

Technical User
Dec 5, 2002
4
US
Hi All,

I am trying to retrieve the names of files from a particular set of folders that are named according to the date the folder was created (e.g. 11-02-02). Now the trouble is that under the parent folder there are often times several subfolders named according to the date created. However, I only want to find the subfolder with the most recent date. For example if the Parent folder contains subfolders name 07-06-02 and 10-07-02 and 11-02-02 I only want to retrieve the filenames for the 11-02-02 folder.

thanks for your help,

Pat
 
Hi

REtrive the names of the folders using the DIR() command (see help for syntax) and either have a little bit od code to simply keep the one with the latest date, or save them into an array and sort the array.

Life would have been easier if you have named then using adtes in the form yymmdd, since tehy would have sorted correctly even as strings, but since you have not done this, you can use the CDate() function to convert the string tp a date, and then sort/test the date values against each other Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hello Ken,

Could you please demonstrate the code to save the dates in an array and then sort the array as you've suggested. I'm working on a similar project at the moment and haven't a clue!

Thanks in advance.
Jane


 
Hi JaneAtWork

how about:

Sub BubbleSort(List() As Integer)
' Sorts an array using bubble sort algorithm

Dim First As Integer, Last As Integer
Dim i As Integer, j As Integer
Dim Temp As Integer

First = LBound(List)
Last = UBound(List)
For i = First To Last - 1
For j = i + 1 To Last
If List(i) > List(j) Then
Temp = List(j)
List(j) = List(i)
List(i) = Temp
End If
Next j
Next i
End Sub
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Ken,

Thanks so much for the feed back. I've already have the code to retrieve the list of folders. What I need to know is how to write the code to select the folder whos name is the most recent. I am trying to search parent folder that contains several subfolders and those subfolders contain folders named according to certain date, keeping in mind that these folders with dates as names are not named after the actual date of the folder was created but rather the date a piece of literature was started. Anyway below is a sample of the structure in tree view.

Parent Folder
subfolder
09-12-02
11-02-02
11-24-02 'this is the folders path I want to retrieve

subfolder
11-05-02
11-12-02
11-16-02
11-23-02 'this is the folders path I want to retrieve

etc., etc.

I want to retrieve these and place the into a listbox.

thanks for your help,
Pat


 
Hi

The sort routine I posted earlier will tell you which is the 'latest' folder.

Suppose we have the list of folder names in an array called FolderNames().

Our first problem as I said earlier is that you have the dates used as folder names formatted as dd-mm-yy, this does not lend itself to sorting since 01-12-02 will come before 30-11-02. It would have been better if you had named your folders with dates in the format yy-mm-dd.

So if you first transform the list so

For i = 0 to uBound(FolderNAmes)
FoldersYYMMDD(i) = Right(FolderNames(i),2) & "-" & Mid(FolderNames(i),4,2) & "-" & Left(FolderNames(i),2)
Next i
' Now Sort the list
BubbleSort FoldersYYMMDD
' and now FoldersYYMMDD(UBound(FoldersYYMMDD)) will be the name of the latest folder (in yymmdd format, just turn it around using left mid etc as above)
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top