Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / November 2008



Tip: Looking for answers? Try searching our database.

sorting files by date/time

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter - 17 Nov 2008 11:08 GMT
Does anybody have a good VB6 sample code that sorts a list of files
retrieved using FindFirstFile/FindNextFile by date/time?
Regards
Peter
Dave O. - 17 Nov 2008 11:37 GMT
> Does anybody have a good VB6 sample code that sorts a list of files
> retrieved using FindFirstFile/FindNextFile by date/time?
> Regards
> Peter

There is no way (to my knowledge) to tell the
FindFirstFile/FindNextFile/FindClose to return files in any order other than
what you get.
So you need to read them in to an array or a ListView or whatever and then
sort them in the usual manner.

Dave O.
Peter - 17 Nov 2008 12:40 GMT
Thanks for your fast answer!
What is the best way to sort the files by date/time:
Should I create a FILETIME array and use API function CompareFileTime() in
my sort routine?
Any sample code available?
Regards
Peter

>> Does anybody have a good VB6 sample code that sorts a list of files
>> retrieved using FindFirstFile/FindNextFile by date/time?
[quoted text clipped - 8 lines]
>
> Dave O.
Dave O. - 17 Nov 2008 13:05 GMT
> Thanks for your fast answer!
> What is the best way to sort the files by date/time:
> Should I create a FILETIME array and use API function CompareFileTime() in
> my sort routine?

You could, but why bother, if you put the timestamp into a date variable you
can compare them directly in the sort routine.
If the data/times are stored as strings you'll need to convert them back to
dates for the sort, alternatively you could convert the date/time to doubles
and sort on those.
It's not all that easy to give exact examples because selecting which
routine would be optimum depends on many factors.

Dave O.
Dave O. - 17 Nov 2008 13:14 GMT
>> Thanks for your fast answer!
>> What is the best way to sort the files by date/time:
>> Should I create a FILETIME array and use API function CompareFileTime()
>> in my sort routine?

I just remembered you MUST apply the FileTimeToLocalFileTime API to the
FileTime structure before you save the value anywhere, this is because the
file stamps are stored in UDT (GMT no summer adjustment) and will need to be
adjusted to your locale.

Regards
Dave O.
Peter - 17 Nov 2008 20:46 GMT
Thanks, but I think I don't need to use FileTimeToLocalFileTime() just to
sort the files by date/time, am I right?
Regards
Peter

>>> Thanks for your fast answer!
>>> What is the best way to sort the files by date/time:
[quoted text clipped - 8 lines]
> Regards
> Dave O.
Thorsten Albers - 17 Nov 2008 22:23 GMT
> Thanks, but I think I don't need to use FileTimeToLocalFileTime() just to

> sort the files by date/time, am I right?

You don't. In addition it is not necessary to call CompareFileTime() since
a FIILETIME is just an increasing 64 bit number. The call to
CompareFileTime() needs more time than a comparison done in you code.

If FT_A.dwHighDateTime <> FT_B.dwHighDateTime Then

 If FT_A.dwHighDateTime >= 0 Then
   If FT_B.dwHighDateTime >= 0 Then
     If FT_A.dwHighDateTime > FT_B.dwHighDateTime Then
       ' A >= 0 / B >= 0 - A > B
     Else
       ' A >= 0 / B >= 0 - A < B
     End If
   Else
     ' A >= 0 / B < 0: A < B
   End If
 ElseIf FT_B.dwHighDateTime >= 0 Then
   ' A < 0 / B >= 0: A > B
 ElseIf FT_A.dwHighDateTime > FT_B.dwHighDateTime Then
   ' A < 0 / B < 0 - A > B
 Else
   ' A < 0 / B < 0 - A < B
 End If

ElseIf FT_A.dwLowDateTime >= 0 Then
 If FT_B.dwLowDateTime >= 0 Then
   If FT_A.dwLowDateTime > FT_B.dwLowDateTime Then
     ' A >= 0 / B >= 0 - A > B
   Else
     ' A >= 0 / B >= 0 - A < B
   End If
 Else
   ' A >= 0 / B < 0: A < B
 End If
ElseIf FT_B.dwLowDateTime >= 0 Then
 ' A < 0 / B >= 0: A > B
ElseIf FT_A.dwLowDateTime > FT_B.dwLowDateTime Then
 ' A < 0 / B < 0 - A > B
Else
 ' A < 0 / B < 0 - A < B
End If

Signature

----------------------------------------------------------------------
Thorsten Albers                               albers(a)uni-freiburg.de
----------------------------------------------------------------------

Larry Serflaten - 18 Nov 2008 00:35 GMT
> Thanks, but I think I don't need to use FileTimeToLocalFileTime() just to
> sort the files by date/time, am I right?
> Regards

You might convert the values to the Decimal type which can handle
those large numbers.  Then  you just compare the two (Decimal)
values.  Conversion might be like:  (not tested)

Private Function ToDecimal(FileTime As FileTimeType) As Variant
Dim hi As Long, lo As Long
Dim hx As String
 hx = Right$("0000000" & Hex(FileTime.Hi), 8)
 hi = Val("&H" & Left$(hx, 4) & "&")
 lo = Val("&H" & Right$(hx, 4) & "&")
 ToDecimal = hi * CDec(65536) + lo
 hx = Right$("0000000" & Hex(FileTime.Lo), 8)
 hi = Val("&H" & Left$(hx, 4) & "&")
 lo = Val("&H" & Right$(hx, 4) & "&")
 ToDecimal = ToDecimal * CDec(4294967296#) + hi * CDec(65536) + lo
End Function

The conversion to Hex was used to properly treat the sign bit as used
in an unsigned value.  Other (all numeric) methods of conversion may be
quicker....

LFS
Peter - 21 Nov 2008 06:55 GMT
Just want to Thank you all for your answers.
I solved the problem by using a Function "FileTimetoserial" which creates a
Date-Variable out of the FileTime Structure.
Then I used these date values in my sort routine.
Regards
Peter

>> Thanks, but I think I don't need to use FileTimeToLocalFileTime() just to
>> sort the files by date/time, am I right?
[quoted text clipped - 22 lines]
>
> LFS
Thorsten Albers - 21 Nov 2008 11:56 GMT
Peter <peter_l@myrealbox.com> schrieb im Beitrag
<gg5m10$cvn$1@mail1.sbs.de>...
> Just want to Thank you all for your answers.
> I solved the problem by using a Function "FileTimetoserial" which creates a
> Date-Variable out of the FileTime Structure.
> Then I used these date values in my sort routine.

What a completely superfluous performance killer...

Signature

----------------------------------------------------------------------
Thorsten Albers                               albers(a)uni-freiburg.de
----------------------------------------------------------------------

Peter - 24 Nov 2008 15:27 GMT
You are right. But I found out that I need the filetime in a variable "as
date" later in my code so I thought I convert it to date immediately.
Regards
Peter

> Peter <peter_l@myrealbox.com> schrieb im Beitrag
> <gg5m10$cvn$1@mail1.sbs.de>...
[quoted text clipped - 5 lines]
>
> What a completely superfluous performance killer...
expvb - 17 Nov 2008 13:24 GMT
> Does anybody have a good VB6 sample code that sorts a list of files
> retrieved using FindFirstFile/FindNextFile by date/time?
> Regards
> Peter

Search for "FindFirstFile" at the following site:

http://vbnet.mvps.org

The site is for VB6 despite its name. As for comparing times, you can use
CompareFileTime, or convert it to a Date data type. For the later, see
FileTimeToVBDate() function here:

http://vbnet.mvps.org/code/fileapi/fsoapicompare.htm
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.