Using the _stat64() and _ctime64_s()/_ctime64() functions reporting a file information

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: Displaying file information

To show: Using the _stat64() and _ctime64_s()/_ctime64() functions reporting a file information

 

 

/* Using the _stat64() and _ctime64_s()/_ctime64() functions reporting a file information */

#include <windows.h>

#include <time.h>

#include <sys.h>

#include <stdio.h>

#define SIZE 26

 

int main(void)

{

struct __stat64 buf[SIZE];

int result;

 

/* char fname[50] = "c:\\WINNT\\system32\\config\\sam.log"; */

char fname[50] = "C:\\windows\\system32\\config\\sam.log";

 

/* Get data associated with a file */

result = _stat64(fname, buf);

 

/* Test if statistics are valid */

if(result != 0)

printf("Problem getting %s file information. Error code: %d.\n", fname, GetLastError());

else

{

/* dump some of the file information */

/* Notice how the structures' elements were accessed */

printf("The file : %s\n", fname);

printf("Drive : %c:\n", buf->st_dev + 'A');

printf("File size : %ld bytes\n", buf->st_size);

 

/* printf("Time created : %s", _ctime64(&buf.st_ctime)); */

_ctime64_s((char*)buf, SIZE, &buf->st_ctime);

printf("Time created : %s", buf);

_ctime64_s((char*)buf, SIZE,&buf->st_atime);

printf("Last accessed : %s", buf);

_ctime64_s((char*)buf, SIZE,&buf->st_mtime);

printf("Time modified : %s", buf);

printf("Bit mask : %p\n", &buf->st_mode);

 

return 0;

}

}

 

Output example:

 

The file : C:\windows\system32\config\sam.log

Drive : C:

File size : 1024 bytes

Time created : Sun Jul 17 04:56:53 2005

Last accessed : Tue Dec 12 20:54:21 2006

Time modified : Tue Dec 12 20:54:21 2006

Bit mask : 0012F9B6

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index