Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Get file size

Get file size

Scheduled Pinned Locked Moved C / C++ / MFC
ios
10 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pl_kode
    wrote on last edited by
    #1

    I am reading the value of the size from the properties file... e.g. file_size=500. I have to check for the file size limit. The max limit is set as done above. During runtime the following function checks for the file size with the above by using the following function to get the current file size.

    int get_file_size()
    {
    long file_size;
    ifstream myfile;
    myfile.open(path.c_str());
    myfile.seekg(0, ios::end);
    file_size = myfile.tellg();
    myfile.close();
    return file_size;
    }

    But if I do this I get the file size in bytes. I want to do everything in kb's. Any suggestion please. THANKS.

    S M C M H 5 Replies Last reply
    0
    • P pl_kode

      I am reading the value of the size from the properties file... e.g. file_size=500. I have to check for the file size limit. The max limit is set as done above. During runtime the following function checks for the file size with the above by using the following function to get the current file size.

      int get_file_size()
      {
      long file_size;
      ifstream myfile;
      myfile.open(path.c_str());
      myfile.seekg(0, ios::end);
      file_size = myfile.tellg();
      myfile.close();
      return file_size;
      }

      But if I do this I get the file size in bytes. I want to do everything in kb's. Any suggestion please. THANKS.

      S Offline
      S Offline
      shaderx
      wrote on last edited by
      #2

      How about:

      return file_size/1024;

      ? :D

      D 1 Reply Last reply
      0
      • P pl_kode

        I am reading the value of the size from the properties file... e.g. file_size=500. I have to check for the file size limit. The max limit is set as done above. During runtime the following function checks for the file size with the above by using the following function to get the current file size.

        int get_file_size()
        {
        long file_size;
        ifstream myfile;
        myfile.open(path.c_str());
        myfile.seekg(0, ios::end);
        file_size = myfile.tellg();
        myfile.close();
        return file_size;
        }

        But if I do this I get the file size in bytes. I want to do everything in kb's. Any suggestion please. THANKS.

        M Offline
        M Offline
        Michael Schubert
        wrote on last edited by
        #3

        Are you kidding?? If not, my suggestion would be: Go back to first grade and start all over again.

        1 Reply Last reply
        0
        • S shaderx

          How about:

          return file_size/1024;

          ? :D

          D Offline
          D Offline
          Doc Lobster
          wrote on last edited by
          #4

          No, that would be a Kibibyte.

          1 Reply Last reply
          0
          • P pl_kode

            I am reading the value of the size from the properties file... e.g. file_size=500. I have to check for the file size limit. The max limit is set as done above. During runtime the following function checks for the file size with the above by using the following function to get the current file size.

            int get_file_size()
            {
            long file_size;
            ifstream myfile;
            myfile.open(path.c_str());
            myfile.seekg(0, ios::end);
            file_size = myfile.tellg();
            myfile.close();
            return file_size;
            }

            But if I do this I get the file size in bytes. I want to do everything in kb's. Any suggestion please. THANKS.

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            Do you know bytes and kilobytes are simply related, don't you? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            M 1 Reply Last reply
            0
            • P pl_kode

              I am reading the value of the size from the properties file... e.g. file_size=500. I have to check for the file size limit. The max limit is set as done above. During runtime the following function checks for the file size with the above by using the following function to get the current file size.

              int get_file_size()
              {
              long file_size;
              ifstream myfile;
              myfile.open(path.c_str());
              myfile.seekg(0, ios::end);
              file_size = myfile.tellg();
              myfile.close();
              return file_size;
              }

              But if I do this I get the file size in bytes. I want to do everything in kb's. Any suggestion please. THANKS.

              M Offline
              M Offline
              Maruf Maniruzzaman
              wrote on last edited by
              #6

              Do you really need to open the file and seek to end to get the size? Why directory informations are for then??

              Maruf Maniruzzaman @ Dhaka, Bangladesh. [Homepage] [Blog] [Silverlight Clone] [Resume]

              1 Reply Last reply
              0
              • P pl_kode

                I am reading the value of the size from the properties file... e.g. file_size=500. I have to check for the file size limit. The max limit is set as done above. During runtime the following function checks for the file size with the above by using the following function to get the current file size.

                int get_file_size()
                {
                long file_size;
                ifstream myfile;
                myfile.open(path.c_str());
                myfile.seekg(0, ios::end);
                file_size = myfile.tellg();
                myfile.close();
                return file_size;
                }

                But if I do this I get the file size in bytes. I want to do everything in kb's. Any suggestion please. THANKS.

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                Why you dont use of CFile::GetLength or GetFileAttributesEx if you dont like to use of them so I tell you a secret that is on the c++ and its:StrFormatByteSizeA . :laugh:

                1 Reply Last reply
                0
                • C CPallini

                  Do you know bytes and kilobytes are simply related, don't you? :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                  M Offline
                  M Offline
                  Michael Schubert
                  wrote on last edited by
                  #8

                  CPallini wrote:

                  kilobytes

                  Kilo is actually metric and means 1000, not 1024. ;P

                  C 1 Reply Last reply
                  0
                  • M Michael Schubert

                    CPallini wrote:

                    kilobytes

                    Kilo is actually metric and means 1000, not 1024. ;P

                    C Offline
                    C Offline
                    CPallini
                    wrote on last edited by
                    #9

                    I know but: (1) It is a controversial point [^](do you manufacture hard disks?). (2) It has no releveance on my statement validity. ;P :-D

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                    M 1 Reply Last reply
                    0
                    • C CPallini

                      I know but: (1) It is a controversial point [^](do you manufacture hard disks?). (2) It has no releveance on my statement validity. ;P :-D

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                      M Offline
                      M Offline
                      Michael Schubert
                      wrote on last edited by
                      #10

                      I was just stating how I interpret the term "kilo", not how the HD manufacturers abuse it for their marketing. Interesting article on Wikipedia, by the way. I think these new IEC (kibi, mebi :omg: ) and Jedec standards are just idiotic. They should simply stick with KB/KByte, MB/MByte.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups