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 can I check a folder to see if there is a specific file exist or not?

How can I check a folder to see if there is a specific file exist or not?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++learning
8 Posts 3 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.
  • S Offline
    S Offline
    StarMeteor
    wrote on last edited by
    #1

    Dear All, I am a new comer of this message board. First let me say hi to you all ^_^ I am working on my project in my school which require me to check if there is any new file exist in a folder by using MFC. Since I am just start learning MFC a few weeks before, I totally have no idea about how I can do so........ Would anyone give me some advice on this in details? Really thanks a lot! Yours, Meteor

    R D 2 Replies Last reply
    0
    • S StarMeteor

      Dear All, I am a new comer of this message board. First let me say hi to you all ^_^ I am working on my project in my school which require me to check if there is any new file exist in a folder by using MFC. Since I am just start learning MFC a few weeks before, I totally have no idea about how I can do so........ Would anyone give me some advice on this in details? Really thanks a lot! Yours, Meteor

      R Offline
      R Offline
      RadioShark
      wrote on last edited by
      #2

      Hi, CFile f; char* pFileName = "test.dat"; if( !f.Open( pFileName, CFile::modeRead | CFile::shareDenyNone ) ) { #ifdef _DEBUG afxDump << "File could not be opened " << "\n"; #endif } Sincerely Yours, RadioShark

      S 1 Reply Last reply
      0
      • S StarMeteor

        Dear All, I am a new comer of this message board. First let me say hi to you all ^_^ I am working on my project in my school which require me to check if there is any new file exist in a folder by using MFC. Since I am just start learning MFC a few weeks before, I totally have no idea about how I can do so........ Would anyone give me some advice on this in details? Really thanks a lot! Yours, Meteor

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

        How about _access(), or CFile::GetStatus()?


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        1 Reply Last reply
        0
        • R RadioShark

          Hi, CFile f; char* pFileName = "test.dat"; if( !f.Open( pFileName, CFile::modeRead | CFile::shareDenyNone ) ) { #ifdef _DEBUG afxDump << "File could not be opened " << "\n"; #endif } Sincerely Yours, RadioShark

          S Offline
          S Offline
          StarMeteor
          wrote on last edited by
          #4

          Oh....I forget to mention that I have to check it continuously, i.e. when I start the program, I have to be able to check it after clicking "Start" button and it will loop continuously to check..... Will your method be ok on that also? ^_^ Yours, Meteor

          D 1 Reply Last reply
          0
          • S StarMeteor

            Oh....I forget to mention that I have to check it continuously, i.e. when I start the program, I have to be able to check it after clicking "Start" button and it will loop continuously to check..... Will your method be ok on that also? ^_^ Yours, Meteor

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

            StarMeteor wrote: ...and it will loop continuously to check... If that is your requirement, use ReadDirectoryChangesW() and/or FindFirstChangeNotification() instead. Unless it is done infrequently, polling the OS in a loop is not very efficicent.


            "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

            S 1 Reply Last reply
            0
            • D David Crow

              StarMeteor wrote: ...and it will loop continuously to check... If that is your requirement, use ReadDirectoryChangesW() and/or FindFirstChangeNotification() instead. Unless it is done infrequently, polling the OS in a loop is not very efficicent.


              "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

              S Offline
              S Offline
              StarMeteor
              wrote on last edited by
              #6

              Oh.....actually I have looked in this site and read an article about the API you mentioned...but I don't understand it much....especially what I need to use it and how to initialize ..... :sigh:T_T

              D 1 Reply Last reply
              0
              • S StarMeteor

                Oh.....actually I have looked in this site and read an article about the API you mentioned...but I don't understand it much....especially what I need to use it and how to initialize ..... :sigh:T_T

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

                fwatch.exe is a good example.


                "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                S 1 Reply Last reply
                0
                • D David Crow

                  fwatch.exe is a good example.


                  "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                  S Offline
                  S Offline
                  StarMeteor
                  wrote on last edited by
                  #8

                  Oh...I found that I forget to defind #define _WIN32_WINNT 0x400 at stdafx.h in order to use the API.... I can use it now! Thanks a lot~

                  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