Solved

Using GetFileTime without having to CreateFile first

Posted on 1998-11-17
4
741 Views
Last Modified: 2013-12-03
I am making extensive use of GetFileTime but have to use CreateFile to get the file handle.  Am I right in thinking this will slow things down because the file is being opened every time ?  Is there a waya round this that may speed things up ?
0
Comment
Question by:ssherlock
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
trillo earned 100 total points
ID: 1416150
Yes, I think you're right, you may be loosing a lot of time. Try with the following function:

BOOL GetFileAttributesEx (
   LPCTSTR lpFileName,
   GET_FILEEX_INFO_LEVELS fInfoLevelId,
   LPVOID lpFileInformation );

pFileName = Pointer to a null-terminated string that specifies a file or directory.
fInfoLevelId = Enumeration type value that specifies the set of attribute information to obtain. (GetFileExInfoStandard)
lpFileInformation = Pointer to a buffer that receives the attribute information. (WIN32_FILE_ATTRIBUTE_DATA)


typedef struct _WIN32_FILE_ATTRIBUTE_DATA{  
    DWORD      dwFileAttributes;
    FILETIME   ftCreationTime;
    FILETIME   ftLastAccessTime;
    FILETIME   ftLastWriteTime;
    DWORD      nFileSizeHigh;
    DWORD      nFileSizeLow;
}

Actually I took this from the SDK help files (if you don't have the, just tell me and I'll send you all you need about this function).

trillo
0
 

Author Comment

by:ssherlock
ID: 1416151
Thanks, I don't have MSDN installed here due to disk space.  Could you give a small example ?

Cheers, Simon.
0
 
LVL 2

Expert Comment

by:trillo
ID: 1416152
You should use next code:

WIN32_FILE_ATTRIBUTE_DATA *wfad;
GetFileAttributesEx ("d:/any.txt", GetFileExInfoStandard, &wfad);

I just tried it in VC++ and didn't work, I got next message:
"Cannot execute TEST.EXE .... linked to Kernel32.GetFileAttributesEx ... does not exist."
Althoug I had no problems while compiling. There could be something wrong with my Kernel (or maybe a bad version).

Anyway, if it doesn't work with you then I accept I couldn't help very much, so you can reject my answer.

Trillo.
0
 
LVL 1

Expert Comment

by:hustch
ID: 1416153
I've had the same problem, and GetFileAttributesEx is the fastest way, but it only works in Windows NT, not Windows 95.

I use CreateFile/GetFileTime, which is a lot faster than than FindFirst. You can pass a zero for dwDisiredAccess to CreateFile if you need to minimize sharing problems.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question