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. How to get file-size of a file?

How to get file-size of a file?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
6 Posts 4 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.
  • M Offline
    M Offline
    Monisankar
    wrote on last edited by
    #1

    How can i implement one function to get the file size of a file which takes pointer to the file path?Please help..

    M D H 3 Replies Last reply
    0
    • M Monisankar

      How can i implement one function to get the file size of a file which takes pointer to the file path?Please help..

      M Offline
      M Offline
      Martin Koorts
      wrote on last edited by
      #2

      Hi Using Win32, you can use FindFirstFile and inspect the WIN32_FIND_DATA structure returned from that (and call FindClose when you leave). In .NET, that information is available from the FileInfo class. HTH Martin

      1 Reply Last reply
      0
      • M Monisankar

        How can i implement one function to get the file size of a file which takes pointer to the file path?Please help..

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Why not use GetFileSize()?


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        M 1 Reply Last reply
        0
        • D David Crow

          Why not use GetFileSize()?


          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          M Offline
          M Offline
          Monisankar
          wrote on last edited by
          #4

          The function should take only the constant pointer to the path of the file..

          D 1 Reply Last reply
          0
          • M Monisankar

            The function should take only the constant pointer to the path of the file..

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Ok, what's wrong with:

            DWORD SizeOfFile( LPCTSTR lpszFile )
            {
            DWORD dwSize = 0;
            HANDLE hFile;

            hFile = CreateFile(lpszFile, 0, 0, NULL, OPEN\_EXISTING, ...);
            if (hFile != INVALID\_HANDLE\_VALUE)
            {
                dwSize = GetFileSize(hFile, NULL); // you may want to use GetFileSizeEx() instead
                CloseHandle(hFile);
            }
            
            return (dwSize);
            

            }


            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            1 Reply Last reply
            0
            • M Monisankar

              How can i implement one function to get the file size of a file which takes pointer to the file path?Please help..

              H Offline
              H Offline
              HurricaneFlossie
              wrote on last edited by
              #6

              Try CFile myFile(lpszFileName, CFile::modeRead); int len = myFile.GetLength(); Some people see things that are and ask, Why? Some people dream of things that never were and ask, Why not? Some people have to go to work and don't have time for all that ... Author: George Carlin

              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