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!

sorting files by date time

Status
Not open for further replies.

finglem

Technical User
Nov 14, 2003
66
0
0
GB
Hi Guys, I hope someone here can point me in the right direction.
I need to be able to sort a list of filenames in a directory by date and time. I know I can use ADIR to get a list of the files into an array and I can use ASORT to sort by the date the file was last modified or the time the file was last modified but how would I use ASORT to sort by date AND time?
I may be overlooking something really simple (not unusual) but if anybody can give me a clue it would be appreciated.
Thanks
 
Create a new array, with a column for the DATETIME(). Copy the ADIR() array to the new array, and sort it.

For example:

Code:
lnCount = ADIR(laBase, <skeleton>)
DIMENSION laFiles(lnCount, 2)
FOR lnI = 1 TO lnCount
  laFiles(lnI, 1) = laBase(lnI, 1)  && filename
  laFiles(lnI, 2) = ;
    CTOT(TRANSFORM(laBase(lnI, 3) + " " + laBase(lnI, 4))
                                    && timestamp
ENDFOR

You now have an array with the filename in the first column, and the full timestamp in the second. Use ASORT() to sort on the second column.

I haven't tested this code. You might need to tweak it, depending on your date and strictdate settings.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks for that Mike

I'll give it a go and let you know how I get on.

Thanks again
 
Excellent!!! Thanks Mike it works a treat.

Slight alteration, as you suggested but it's just what I need.

Thanks again Mike you're a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top