Forum Discussion
Can you check file size locally without hydrating?
- Oct 27, 2026
Yes. The first thing to change is GENERIC_READ: it requests access to file contents as well as metadata. For this query, request only FILE_READ_ATTRIBUTES.
HANDLE hff = CreateFileW( fn.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr ); if (hff == INVALID_HANDLE_VALUE) { const DWORD error = GetLastError(); errno = ERRNO_FROM_WIN32(error); return -1; } BY_HANDLE_FILE_INFORMATION info{}; if (!GetFileInformationByHandle(hff, &info)) { const DWORD error = GetLastError(); CloseHandle(hff); errno = ERRNO_FROM_WIN32(error); return -1; } CloseHandle(hff); const ULONGLONG fileSize = (static_cast<ULONGLONG>(info.nFileSizeHigh) << 32) | info.nFileSizeLow;
For a locally present OneDrive Files On-Demand placeholder, this metadata-only access should avoid downloading its contents. The reported size is the logical file size, not the space currently occupied on disk.
If you only need size and timestamps, GetFileAttributesExW is another option that doesn’t require opening a handle.
One caveat: the file index is a local filesystem identifier, not a persistent OneDrive cloud ID. Last-access timestamps also follow Windows filesystem update rules, so they aren’t a reliable record of when someone last viewed the cloud file.
Reference: CreateFileW access rights.
Yes. The first thing to change is GENERIC_READ: it requests access to file contents as well as metadata. For this query, request only FILE_READ_ATTRIBUTES.
HANDLE hff = CreateFileW( fn.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr ); if (hff == INVALID_HANDLE_VALUE) { const DWORD error = GetLastError(); errno = ERRNO_FROM_WIN32(error); return -1; } BY_HANDLE_FILE_INFORMATION info{}; if (!GetFileInformationByHandle(hff, &info)) { const DWORD error = GetLastError(); CloseHandle(hff); errno = ERRNO_FROM_WIN32(error); return -1; } CloseHandle(hff); const ULONGLONG fileSize = (static_cast<ULONGLONG>(info.nFileSizeHigh) << 32) | info.nFileSizeLow;
For a locally present OneDrive Files On-Demand placeholder, this metadata-only access should avoid downloading its contents. The reported size is the logical file size, not the space currently occupied on disk.
If you only need size and timestamps, GetFileAttributesExW is another option that doesn’t require opening a handle.
One caveat: the file index is a local filesystem identifier, not a persistent OneDrive cloud ID. Last-access timestamps also follow Windows filesystem update rules, so they aren’t a reliable record of when someone last viewed the cloud file.
Reference: CreateFileW access rights.
- jblum2000Oct 28, 2026Copper Contributor
That's great news! For what it's worth, since I posted this, I found an alternate method which also works: open a handle to the parent folder, then use NtQueryDirectoryFileEx with the folder handle to iterate through the files and check their attributes. But your approach is obviously simpler in pretty much all cases!