Solved

Using GetFileTime without having to CreateFile first

Posted on 1998-11-17
4
724 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now