I guess you'd have to write this function and I can't think of a 'C standard' solution off hand. I do think the following should work on VC6 and any TC / TC++ that had stat.h. You might have to make some minor changes as I tested this in DevC++ (4.9.9.2)
Regards,
Brian
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include <io.h>
int main(int argc, char *argv[])
{
struct stat *c; // attribute structure
time_t t;
char str[41],timestr[40];
int err;
printf("Enter filename: ");
fgets(str, 40, stdin);
// crop newline out of string
str[strlen(str) - 1] = '\0';
err = stat(str,c); // get file attributes
if (err == -1)
{
printf("\nError in stat\n");
printf("\nPress `Enter' to continue . . . ");
getchar();
return(1);
}
// show creation date
t = c->st_ctime;
strcpy(timestr,ctime(&t));
printf("\nDate created = %s\n",timestr);
// get modification date
// GNU C manual: This is the time of the last modification to
// the contents of the file.
t = c->st_mtime;
strcpy(timestr,ctime(&t));
printf("Date modified = %s\n",timestr);
// get the last time file was accessed
// GNU C manual: This is the last access time for the file
t = c->st_atime;
strcpy(timestr,ctime(&t));
printf("Time file was last accessed = %s\n",timestr);
// display file size
printf("File size = %li bytes\n", c->st_size);
#define EXIST 0
#define WRITE_ONLY 2
#define READ_ONLY 4
#define READ_WRITE 6
// Check that file exist:
if(!access(str, EXIST))
{
printf( "\nFile %s exists.\n\n", str );
// Check read and write permissions
if(!access( str, READ_WRITE))
printf( "File %s is READ_WRITE.\n", str );
else
{
if(!access( str, WRITE_ONLY))
printf( "File %s is WRITE_ONLY.\n", str );
if(!access( str, READ_ONLY))
printf( "File %s is READ_ONLY.\n", str );
}
}
printf("\nPress `Enter' to continue . . . ");
getchar();
return 0;
}