#include#include int main() { LPCWSTR file_path = L"C:\\example.txt"; HANDLE file_handle = CreateFile(file_path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (file_handle == INVALID_HANDLE_VALUE) { std::cout << "Failed to open file" << std::endl; return 1; } BY_HANDLE_FILE_INFORMATION file_info; GetFileInformationByHandle(file_handle, &file_info); DWORD fileId = file_info.nFileIndexLow; std::cout << "File Id: " << fileId << std::endl; CloseHandle(file_handle); return 0; }
#includeIn this example, we use the Boost FileSystem library to access the fileId of a file called example.txt. We use the status function to retrieve the file status and the file_id function to retrieve the fileId. This code requires the Boost library.#include int main() { boost::filesystem::path file_path{"example.txt"}; boost::filesystem::file_status file_status = boost::filesystem::status(file_path); boost::filesystem::file_id_info file_id = file_status.file_id(); std::cout << "File Id: " << file_id << std::endl; return 0; }