Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 797
  • Last Modified:

Using GetFileTime without having to CreateFile first

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
ssherlock
Asked:
ssherlock
  • 2
1 Solution
 
trilloCommented:
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
 
ssherlockAuthor Commented:
Thanks, I don't have MSDN installed here due to disk space.  Could you give a small example ?

Cheers, Simon.
0
 
trilloCommented:
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
 
hustchCommented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now