File::getLastModificationTime() very slow


#1

File::getLastModificationTime() is very slow on Windows (about 15-30 files per second). Is there a better (yet simple) way to retrieve last modification dates for a random list of files?


#2

Here’s the solution for fast last modification time & file size retrieval for Win32: Using Win32’s GetFileAttributesEx() instead of Win32’s GetFileTime().

Could be added to JUCE. The speedup is about 100 times, so it’s definately worth it. I think the major speedup comes from the fact that the file has not to be opened prior to getting the information.

// function returns false if something went wrong. Please note that the file you pass must exist or otherwise strange results may occur!

bool getFileAttributes(File &file, int64 &lastModificationTime, int64 &fileSize)
{
#if JUCE_WIN32
WIN32_FILE_ATTRIBUTE_DATA inf;
if (GetFileAttributesEx(file.getFullPathName().toUTF8(),GetFileExInfoStandard,&inf))
{
FILETIME tim=inf.ftLastWriteTime;

	lastModificationTime= (int64(tim.dwHighDateTime)<<32) | int64(tim.dwLowDateTime);
	fileSize= (int64(inf.nFileSizeHigh)<<32) | int64(inf.nFileSizeLow);
	return true;
}
return false;

#else
fileSize=file.getSize();
lastModificationTime=file.getLastModificationTime().toMilliseconds();
return true;
#endif
}


#3

Oh right, I didn’t know it was so slow! Thanks, I’ll sort get that sorted out!