Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to get file created time using stat() function in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>     

int main()
{
    char file[100] = "d:\\data.txt";
	struct stat stats;
	struct tm dt;

	printf("File: %s\n", file);
	
    if (stat(file, &stats) == 0) {
        dt = *(gmtime(&stats.st_ctime));
		printf("Created on: %d-%d-%d %d:%d:%d", dt.tm_mday, dt.tm_mon, dt.tm_year + 1900, 
                                                dt.tm_hour, dt.tm_min, dt.tm_sec);
    }
    else {
        printf("Unable to get file created time\n");
    }
    
    return 0;
}
        
          
          
          
/*
run:
          
File: d:\data.txt
Created on: 12-6-2020 7:35:3
       
*/

 



answered Jul 12, 2020 by avibootz

Related questions

1 answer 168 views
1 answer 170 views
1 answer 638 views
1 answer 215 views
2 answers 187 views
187 views asked Mar 24, 2021 by avibootz
1 answer 208 views
...