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
question
4 Posts 2 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I am trying to get the file size, with code:

    ::FindFirstFile((LPCTSTR)strFileSpec, &fd);
    LARGE_INTEGER size;
    size.HighPart = fd.nFileSizeHigh;
    size.LowPart = fd.nFileSizeLow;
    DWORD dwsize = (DWORD)size.QuadPart;

    but is not right when the size of the file is huge, because at a file with 7.8 GB in windows explorer, my code says that has 3.03 GB ... I have tried with this code too:

    				CFileStatus status;
    				CFile::GetStatus(strFileName, status);
    				DWORD dwsize = (DWORD)status.m\_size);
    

    the same result ... what I am doing wrong ? My OS is Win10 64 bit.

    CPalliniC 1 Reply Last reply
    0
    • _ _Flaviu

      I am trying to get the file size, with code:

      ::FindFirstFile((LPCTSTR)strFileSpec, &fd);
      LARGE_INTEGER size;
      size.HighPart = fd.nFileSizeHigh;
      size.LowPart = fd.nFileSizeLow;
      DWORD dwsize = (DWORD)size.QuadPart;

      but is not right when the size of the file is huge, because at a file with 7.8 GB in windows explorer, my code says that has 3.03 GB ... I have tried with this code too:

      				CFileStatus status;
      				CFile::GetStatus(strFileName, status);
      				DWORD dwsize = (DWORD)status.m\_size);
      

      the same result ... what I am doing wrong ? My OS is Win10 64 bit.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Quote:

      the same result ... what I am doing wrong ?

      Using a DWORD (dwsize) for storing the value. The size of such 'huge files' simply doesn't fit in a DWORD (it is 32-bit wide, see Windows Data Types - Windows applications | Microsoft Docs[^]). Use a 64-bit data type (like DWORD64 or DWORDLONG).

      In testa che avete, signor di Ceprano?

      _ 1 Reply Last reply
      0
      • CPalliniC CPallini

        Quote:

        the same result ... what I am doing wrong ?

        Using a DWORD (dwsize) for storing the value. The size of such 'huge files' simply doesn't fit in a DWORD (it is 32-bit wide, see Windows Data Types - Windows applications | Microsoft Docs[^]). Use a 64-bit data type (like DWORD64 or DWORDLONG).

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Yes, that was the problem. Thank you.

        CPalliniC 1 Reply Last reply
        0
        • _ _Flaviu

          Yes, that was the problem. Thank you.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          You are welcome.

          In testa che avete, signor di Ceprano?

          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