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.

40,026 questions

51,982 answers

573 users

How to get file size and dates from struct stat in C

1 Answer

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

int main() {
    const char* filename = "d:\\data.txt";

    struct stat st;

    if (stat(filename, &st) == -1) {
        perror("stat");
        exit(EXIT_FAILURE);
    }

    printf("File size: %lu bytes\n", st.st_size);
    printf("Last change: %s", ctime(&st.st_ctime));
    printf("Last access: %s", ctime(&st.st_atime));
    printf("Last modification: %s", ctime(&st.st_mtime));

    return 0;
}





/*
run

File size: 40 bytes
Last change: Sun Jul 12 10:35:03 2020
Last access: Sun May 02 16:46:35 2021
Last modification: Sun Jul 12 10:35:03 2020

*/

 



answered May 2, 2021 by avibootz
edited May 2, 2021 by avibootz

Related questions

...