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. C++ File properties

C++ File properties

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++question
9 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.
  • B Offline
    B Offline
    bugDanny
    wrote on last edited by
    #1

    Does anyone know how to access a file's properties in C++? For example, I need to get the time stamp off of some files in my program. (Any other properties would be helpful for me in the future as well.) Danny

    D M 2 Replies Last reply
    0
    • B bugDanny

      Does anyone know how to access a file's properties in C++? For example, I need to get the time stamp off of some files in my program. (Any other properties would be helpful for me in the future as well.) Danny

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

      Try GetFileAttributesEx().


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      B 1 Reply Last reply
      0
      • B bugDanny

        Does anyone know how to access a file's properties in C++? For example, I need to get the time stamp off of some files in my program. (Any other properties would be helpful for me in the future as well.) Danny

        M Offline
        M Offline
        Marc Soleda
        wrote on last edited by
        #3

        File Management[^]: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

        B 2 Replies Last reply
        0
        • D David Crow

          Try GetFileAttributesEx().


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          B Offline
          B Offline
          bugDanny
          wrote on last edited by
          #4

          Thank you. Danny

          1 Reply Last reply
          0
          • M Marc Soleda

            File Management[^]: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

            B Offline
            B Offline
            bugDanny
            wrote on last edited by
            #5

            I take it there's a header file that is needed for the above functions? Danny

            M 1 Reply Last reply
            0
            • B bugDanny

              I take it there's a header file that is needed for the above functions? Danny

              M Offline
              M Offline
              Marc Soleda
              wrote on last edited by
              #6

              no, you don't need to include any other header. They are all already in the standard platform win32 sdk. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

              1 Reply Last reply
              0
              • M Marc Soleda

                File Management[^]: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

                B Offline
                B Offline
                bugDanny
                wrote on last edited by
                #7

                marcdev wrote: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... When using, for example, GetFileTime, MSDN says I need to get a handle to the file by opening it with GENERIC_READ only. I tried both fstream.open() and fopen() ways of opening the file, both with read only selected. It doesn't seem to work (The call to GetFileTime always fails). How am I to get GetFileTime() to work? Danny

                B M 2 Replies Last reply
                0
                • B bugDanny

                  marcdev wrote: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... When using, for example, GetFileTime, MSDN says I need to get a handle to the file by opening it with GENERIC_READ only. I tried both fstream.open() and fopen() ways of opening the file, both with read only selected. It doesn't seem to work (The call to GetFileTime always fails). How am I to get GetFileTime() to work? Danny

                  B Offline
                  B Offline
                  Blake Miller
                  wrote on last edited by
                  #8

                  You need to open the file with the CreateFile Win32 function and it will return a handle to use with the other functions. Don't intermix the different stream, FILE*, etc. families of file function calls together.

                  1 Reply Last reply
                  0
                  • B bugDanny

                    marcdev wrote: GetFileSize, GetFileTime, GetFileAttributesEx, GetFullPathName, GetFileType, ... When using, for example, GetFileTime, MSDN says I need to get a handle to the file by opening it with GENERIC_READ only. I tried both fstream.open() and fopen() ways of opening the file, both with read only selected. It doesn't seem to work (The call to GetFileTime always fails). How am I to get GetFileTime() to work? Danny

                    M Offline
                    M Offline
                    Marc Soleda
                    wrote on last edited by
                    #9

                    FILETIME ftCreation, ftLastAccess, ftLastWrite; HANDLE hFile = CreateFile(filename,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0); if (hFile != INVALID_HANDLE_VALUE) { BOOL bret = GetFileTime(hFile,&ftCreation,&ftLastAccess,&ftLastWrite); } Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

                    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