Solved

Using GetFileTime without having to CreateFile first

Posted on 1998-11-17
4
750 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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