Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C++ (https://www.askmehelpdesk.com/forumdisplay.php?f=439)
-   -   To find size of a file (https://www.askmehelpdesk.com/showthread.php?t=123148)

  • Aug 26, 2007, 10:57 PM
    ejas_6r
    To find size of a file
    Hi,
    I need a help in C++ programming
    In program - I want to make empty a log file depending upon its size(eg 10Mb)
  • Aug 26, 2007, 11:08 PM
    retsoksirhc
    I'm not too familiar with C++, but I have done PHP... I don't recall a file size function. One way to find it might to just to open the file in append mode, and then get the current file pointer. I *think* youn can do that in C, but like I said, I don't program with it.
  • Aug 27, 2007, 12:52 PM
    asterisk_man
    Look up the stat() command.
    I think something like this will work.

    Code:

    #include <sys/stat.h>
    #include <sys/types.h>

    main()
    {
      struct stat sbuf;
      stat("yourfilenamehere",&sbuf);
      printf("Your file is %d bytes\n" sbuf.st_size);
    }

  • Aug 27, 2007, 12:58 PM
    retsoksirhc
    Quote:

    Originally Posted by asterisk_man
    Asterisk man, asterisk man, doing the things an asterisk can, they have a fight, asterisk wins, asterisk man. Bahdubbadubbadubbadubbadubbaduh-bah-bah. - Capuchin

    Is he a dot or is he a spec? If he's underwater does he get wet, or does the water get him instead? Asterisk man...

  • All times are GMT -7. The time now is 11:19 PM.