Microsoft Development
--
Questions
--
Followers
Top Experts
// Try with GetFileTime, fast but I think it may fail if file is locked, but I haven't been able to provoke it
TimeFound = 0;
h = CreateFile(FileName, 0, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (h >= 0) {
if (GetFileTime(h, CreateTime, LastAccess, LastWrite)) {
TimeFound = 1;
}
}
if (!TimeFound) {
// Get time using FindFirstFile, slow but don't care if file locked.
}
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
The "FILE_SHARE_READ or FILE_SHARE_WRITE" should be expressed as "FILE_SHARE_READ || FILE_SHARE_WRITE" in C or C++, however.
If you are looking for one function call:
On Windows NT 4.0 or later, you can use the GetFileAttributesEx function to get the information.
You can also use FindFirstFile. But you have to use FindClose.
By the way, it should be | instead of ||.
"FILE_SHARE_READ | FILE_SHARE_WRITE"
Chensu got me thinking too. Looking at what you had I was lured into thinking that by opening the file with CreateFile() the OS would not have to search the directory tree and would therefore be faster. That was stupid on my part. The OS will still search, only it will do it on the open rather than on the procedure that gets the time. In addition there is considerable overhead for opening and closing a file. You are probably best off just using FindFirstFile (and associated procedures) in all cases.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I know I have to use FindClose.
By faster, I mean shorter execution times.
The CreateFile is a lot faster, I don't know why, but I timed it. There is a lot of files in the directory.
The parameters to CreateFile was chosen in an attempt to avoid sharing problems.
I'll try GetFileAttributesEx
When you use FindFirstFile(), do you use a path that specifcally indicates the file? You don't use wildcards and then look fo the file do you?
It is what i wanted when I started, but I can't find using Delphi help, but I found it using MSVC++ help.
chensu, make an answer with GetFileAtttibutesEx, and I will accept it.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Microsoft Development
--
Questions
--
Followers
Top Experts
Most development for the Microsoft platform is done utilizing the technologies supported by the.NET framework. Other development is done using Visual Basic for Applications (VBA) for programs like Access, Excel, Word and Outlook, with PowerShell for scripting, or with SQL for large databases.