Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to manipulate FILETIME structure...

2,244 views
Skip to first unread message

Christopher Jackson

unread,
Jul 13, 2002, 8:00:01 PM7/13/02
to
I'm trying to make a program that searches a directory for files added after
a certain time (ie. within last ten minutes, within last hour, etc). MSDN
recommends converting FILETIME structures into ULARGE_INTEGER structures and
then doing 64-bit arithmetic to get the desired time. I have not the
slightest clue on how to do this. My psuedo-code so far looks like this:

// Get current system time and convert to file time
SYSTEMTIME st;
FILETIME ft;
GetSystemTime( &st );
SystemTimeToFileTime( &st, &ft );


// convert to FILETIME to ULARGE_INTEGER
// don't have code in front of me, so guessing what names of variables. But
you get the idea

ULARGE_INTEGER uli;
uli.High = ft.dwHighPart;
uli.Low = ft.dwLowPart;

// HERE'S WHERE I NEED HELP
uli.High -= 1; // from my dinking around, I found this subtracts about 7
minutes

// Convert back to FILETIME
ft.dwHighPart = ft.dwHighPart;
ft.dwLowPart = ft.dwLowPart;

// Search directory for files greater than ft
...

Anyone know how to subtract minutes from the FILETIME structure?

TIA


Unknown

unread,
Jul 13, 2002, 9:49:08 PM7/13/02
to

This works:

SYSTEMTIME st;
FILETIME ft;
GetSystemTime (&st);
SystemTimeToFileTime (&st, &ft);

ULARGE_INTEGER uli;
uli.HighPart = ft.dwHighDateTime;
uli.LowPart = ft.dwLowDateTime;

// the number of 100-nanosecond intervals in x seconds is
// x * 10^7 . To set the FILETIME struct back 10 min you must subtract
// 10*60*10^7 = 6 * 10^9.

uli.QuadPart -= 6000000000;

// Convert back to SYSTEMTIME
ft.dwHighDateTime = uli.HighPart;
ft.dwLowDateTime = uli.LowPart;
FileTimeToSystemTime (&ft, &st);


Robert S.

Bret Wood

unread,
Jul 14, 2002, 12:40:48 AM7/14/02
to
In article <5a3Y8.501155$352.83400@sccrnsc02>, chrisjackson1976
@hotmail.com says...

>
> Anyone know how to subtract minutes from the FILETIME structure?

From MSDN --
Visual Studio 6.0 Documentation
Visual C++ Documentation
Reference
MFC Library and Templates
MFC Library
Class Library Reference
Structures, Styles, Callbacks, and Message Maps
Structures Used by MFC
FILETIME Structure

"The FILETIME structure is a 64-bit value representing the number of
100-nanosecond intervals since January 1, 1601."


1 minute is 60,000,000,000 nanoseconds.
So, there are 600,000,000 100-nanosecond "ticks" per minute.

Now you can do something like this:

const ULONGLONG minutesPerTick 600000000;

// Get current system time and convert to file time
SYSTEMTIME st;
FILETIME ft;
GetSystemTime( &st );
SystemTimeToFileTime( &st, &ft );

// convert to FILETIME to ULARGE_INTEGER

ULARGE_INTEGER uli;
uli.High = ft.dwHighPart;
uli.Low = ft.dwLowPart;

uli.QuadPart -= numMinutes * minutesPerTick;

// Convert back to FILETIME
ft.dwHighPart = ft.dwHighPart;
ft.dwLowPart = ft.dwLowPart;

Good luck,

-Bret

--
- Bret Wood
- Grass Valley Group / Thomson Multimedia Broadcast Solutions
- bret...@grassvalleygroup.com

Matti Vuori

unread,
Jul 14, 2002, 6:09:24 AM7/14/02
to
"Christopher Jackson" <chrisjac...@hotmail.com> wrote in
news:5a3Y8.501155$352.83400@sccrnsc02:

> I'm trying to make a program that searches a directory for files added
> after a certain time (ie. within last ten minutes, within last hour,
> etc). MSDN recommends converting FILETIME structures into
> ULARGE_INTEGER structures and then doing 64-bit arithmetic to get the
> desired time. I have not the slightest clue on how to do this. My
> psuedo-code so far looks like this:
>

> // convert to FILETIME to ULARGE_INTEGER
> // don't have code in front of me, so guessing what names of
> variables. But you get the idea

You can get much cleaner code if you use __int64 data type.

Lets make a pointer so the FILETIME struct will be manipulated directly;
__int64 *i = (__int64 *)&ft;

// Now, lets substract five minutes. In nanoseconds one minute would be
__int64 one_minute = (__int64)1e7 * 60; // 60 seconds per minute

*i -= (__int64) 5 * one_minute;

Done!

--
Matti Vuori, <http://sivut.koti.soon.fi/mvuori/index-e.htm>

Christopher Jackson

unread,
Jul 14, 2002, 6:45:09 PM7/14/02
to
Thanks, Robert, Bret, and Matti! I'll give these a try and post my results!
I didn't know I could just manipulate the QuadPart after using the High and
Low parts of the ULARGE_INTEGER union type. Thanks!

"Christopher Jackson" <chrisjac...@hotmail.com> wrote in message
news:5a3Y8.501155$352.83400@sccrnsc02...

andyg...@gmail.com

unread,
Mar 12, 2018, 10:54:41 AM3/12/18
to
The MSDN documentation specifically states that:

"Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows."

So Matti's 'clean' solution is no good.

Andy

Kaz Kylheku

unread,
Mar 12, 2018, 12:28:22 PM3/12/18
to
You replied to a posting from 2002 without proper attribution/quoting.

1. There was no 64 bit windows in 2002. According to the Wikipedia,
the first release of a 64 bit Windows was in 2005:
https://en.wikipedia.org/wiki/X86-64#Windows

2. There are no alignment faults on x86-64; they are disabled by
default. The MSDN wording is probably concerned with the Itanium.
That's a defunct processor that you probably don't have to
worry about.

3. If you have alignment faults, the technique is still possible; just
ensure that the object is aligned to 64 bits. One way it will be
aligned is if it comes from malloc; there are other ways.

Regarding (2), see this StackOverflow:

https://stackoverflow.com/questions/26919269/how-to-enable-alignment-exceptions-for-my-process-on-x64

--
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1

m.laba...@gmail.com

unread,
Mar 27, 2018, 9:50:16 AM3/27/18
to
Hi,

> SYSTEMTIME st;
> FILETIME ft;
> GetSystemTime( &st );
> SystemTimeToFileTime( &st, &ft );

/* Declare local variable (properly aligned 64 bit variable) */
uint64_t ft_uint64;

assert(sizeof(ft_uint64) == sizeof(ft)); /* static assert is better */

/* Copy content from unaligned FILETIME to aligned ft_uint64 */
memcpy(&ft_uint64, &ft, sizeof(ft_uint64));

/* do whatever you want with 'ft_uint64' value */

if (ft_uint64 == 0x112341243ll)
{
...
}

Regards

--
Maciej Labanowicz
0 new messages