Shaitan00 Posted July 19, 2007 Posted July 19, 2007 I have two FILETIME (using System.Runtime.InteropServices;) variables that contain File Times and I need to compare the two to find out who is never. In the past (VC++6) I would simply use [-1 == CompareFileTime (&mrft, &ft)] but this doesn't seem to exist in C# [2002] nor am I able to find its replacement. So how does one go about performing a CompareFileTime of two FileTime variables in C#? FILETIME ft, ftMostRecent; ftMostRecent.dwLowDateTime = 0; ftMostRecent.dwHighDateTime = 0; GetFileTime(&ft); if (-1 == CompareFileTime (&ftMostRecent, &ft)) { // ... do something ... // } Specifically I need to know if "ft" is more recent then "ftMostRecent"... Do I (and even can I) DLLImport the function itself (CompareFileTime)? If so how would the DllImport declaration go? And if not what else I can use or what other method can I utilize to get the same result? Any help would be greatly appreciated. Thanks, Quote
Leaders snarfblam Posted July 19, 2007 Leaders Posted July 19, 2007 You can import the CompareFileTime function from the Windows API to use it in C#. C# Code[HorizontalRule]magic hidden text[/HorizontalRule][DllImport("kernel32.dll")] static extern int CompareFileTime ( ____ ref FILETIME lpFileTime1, ____ ref FILETIME lpFileTime2); [HorizontalRule]Why are you quoting me?[/HorizontalRule] Note that the reference operator in C++ becomes the ref keyword in C#... C# Code[HorizontalRule]magic hidden text[/HorizontalRule]if (-1 == CompareFileTime (ref ftMostRecent, ref ft)) { ____ // ... do something ... // }[HorizontalRule]Why are you quoting me?[/HorizontalRule] Quote [sIGPIC]e[/sIGPIC]
Leaders dynamic_sysop Posted July 19, 2007 Leaders Posted July 19, 2007 well you can use a couple of easy ways way 1: [size=2] [/size][size=2][color=#2b91af]Console[/color][/size][size=2].WriteLine([/size][size=2][color=#2b91af]DateTime[/color][/size][size=2].Compare(System.IO.[/size][size=2][color=#2b91af]File[/color][/size][size=2].GetCreationTime([/size][size=2][color=#a31515]"C:\\B156_FSM.pdf"[/color][/size][size=2]), System.IO.[/size][size=2][color=#2b91af]File[/color][/size][size=2].GetCreationTime([/size][size=2][color=#a31515]"C:\\YServer.txt"[/color][/size][size=2]))); [/size] basically you will get a return of 1 or -1 ( maybe 0 if both had identical times, but don't quote me on that ) way 2: [size=2][/size][size=2][color=#2b91af]Console[/color][/size][size=2].WriteLine( [/size][size=2][color=#2b91af]DateTime[/color][/size][size=2].Compare([/size][size=2][color=#2b91af]DateTime[/color][/size][size=2].FromFileTime(' the long filetime value here !!! '), [/size][size=2][color=#2b91af]DateTime[/color][/size][size=2].FromFileTime(' the long filetime value here !!! ')) ); [/size][size=2][color=#008000][/color][/size] hope it helps. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.