C++ File properties
-
Does anyone know how to access a file's properties in C++? For example, I need to get the time stamp off of some files in my program. (Any other properties would be helpful for me in the future as well.) Danny
Try
GetFileAttributesEx()
.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
Does anyone know how to access a file's properties in C++? For example, I need to get the time stamp off of some files in my program. (Any other properties would be helpful for me in the future as well.) Danny
File Management[^]: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
-
Try
GetFileAttributesEx()
.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
File Management[^]: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
-
no, you don't need to include any other header. They are all already in the standard platform win32 sdk. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
-
File Management[^]: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
marcdev wrote: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... When using, for example, GetFileTime, MSDN says I need to get a handle to the file by opening it with GENERIC_READ only. I tried both fstream.open() and fopen() ways of opening the file, both with read only selected. It doesn't seem to work (The call to GetFileTime always fails). How am I to get GetFileTime() to work? Danny
-
marcdev wrote: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... When using, for example, GetFileTime, MSDN says I need to get a handle to the file by opening it with GENERIC_READ only. I tried both fstream.open() and fopen() ways of opening the file, both with read only selected. It doesn't seem to work (The call to GetFileTime always fails). How am I to get GetFileTime() to work? Danny
You need to open the file with the
CreateFile
Win32 function and it will return a handle to use with the other functions. Don't intermix the different stream, FILE*, etc. families of file function calls together. -
marcdev wrote: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... When using, for example, GetFileTime, MSDN says I need to get a handle to the file by opening it with GENERIC_READ only. I tried both fstream.open() and fopen() ways of opening the file, both with read only selected. It doesn't seem to work (The call to GetFileTime always fails). How am I to get GetFileTime() to work? Danny
FILETIME ftCreation, ftLastAccess, ftLastWrite; HANDLE hFile = CreateFile(filename,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0); if (hFile != INVALID_HANDLE_VALUE) { BOOL bret = GetFileTime(hFile,&ftCreation,&ftLastAccess,&ftLastWrite); }
Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.