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 check if any specific folder is empty

How to check if any specific folder is empty

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorialquestion
8 Posts 5 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
    sunny_vc
    wrote on last edited by
    #1

    Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.

    Regards, Sunil Kumar

    L I B 4 Replies Last reply
    0
    • S sunny_vc

      Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.

      Regards, Sunil Kumar

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      sunny_vc wrote:

      Is there any API to find folder is empty?

      I don't know of one that does this directly. I think the only way is to use FindFirstFile()[^] and its associate FindNextFile() to enumerate the directory.

      1 Reply Last reply
      0
      • S sunny_vc

        Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.

        Regards, Sunil Kumar

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hi Sunil, You could use the FindFirstFile Function[^] and FindNextFile Function[^] Best Wishes, -David Delaune

        1 Reply Last reply
        0
        • S sunny_vc

          Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.

          Regards, Sunil Kumar

          I Offline
          I Offline
          Iain Clarke Warrior Programmer
          wrote on last edited by
          #4

          In addition to the other replies pointing you at FindFirstFile, what is empty? Does it count as empty if there's only directories there? What if there are directories, but they have / have not got any contents themselves? You don't need to answer me, but you need to ask and answer this question for yourself. Iain.

          I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]

          S 1 Reply Last reply
          0
          • I Iain Clarke Warrior Programmer

            In addition to the other replies pointing you at FindFirstFile, what is empty? Does it count as empty if there's only directories there? What if there are directories, but they have / have not got any contents themselves? You don't need to answer me, but you need to ask and answer this question for yourself. Iain.

            I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]

            S Offline
            S Offline
            sunny_vc
            wrote on last edited by
            #5

            Yeah the case can be considered. But the directory is created by my application and the files are also created by my application. My files doesnt contain any extension. I do not understand how I can use FindFirstFile. FindFirstFile is giving me the valid handle.But FindNextFile is always returning 0, even files are present. what is the reason behind it?

            Regards, Sunil Kumar

            M 1 Reply Last reply
            0
            • S sunny_vc

              Yeah the case can be considered. But the directory is created by my application and the files are also created by my application. My files doesnt contain any extension. I do not understand how I can use FindFirstFile. FindFirstFile is giving me the valid handle.But FindNextFile is always returning 0, even files are present. what is the reason behind it?

              Regards, Sunil Kumar

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

              If you're using MFC you might try something like this:

              BOOL DirHasFiles(CString csDir)
              {
              if (csDir.Right(1) != "\\")
              csDir += "\\";

              csDir += "*.*";

              BOOL bDirHasFiles = FALSE;
              CFileFind ff;
              BOOL bWorking = ff.FindFile(csDir);

              while (bWorking)
              {
              bWorking = ff.FindNextFile();
              if (ff.IsDirectory())
              {
              if (ff.IsDots())
              continue;
              }
              else
              bDirHasFiles == TRUE;
              }

              return bDirHasFiles;
              }

              Edit: For plain WIN32, have a look here: http://msdn.microsoft.com/en-us/library/aa365200%28VS.85%29.aspx[^]

              modified on Thursday, October 29, 2009 8:00 AM

              S 1 Reply Last reply
              0
              • M Michael Schubert

                If you're using MFC you might try something like this:

                BOOL DirHasFiles(CString csDir)
                {
                if (csDir.Right(1) != "\\")
                csDir += "\\";

                csDir += "*.*";

                BOOL bDirHasFiles = FALSE;
                CFileFind ff;
                BOOL bWorking = ff.FindFile(csDir);

                while (bWorking)
                {
                bWorking = ff.FindNextFile();
                if (ff.IsDirectory())
                {
                if (ff.IsDots())
                continue;
                }
                else
                bDirHasFiles == TRUE;
                }

                return bDirHasFiles;
                }

                Edit: For plain WIN32, have a look here: http://msdn.microsoft.com/en-us/library/aa365200%28VS.85%29.aspx[^]

                modified on Thursday, October 29, 2009 8:00 AM

                S Offline
                S Offline
                sunny_vc
                wrote on last edited by
                #7

                Thanks a lot Michael.This is exactly what I am looking for.

                Regards, Sunil Kumar

                1 Reply Last reply
                0
                • S sunny_vc

                  Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.

                  Regards, Sunil Kumar

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

                  PathIsDirectoryEmpty

                  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