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 remove a folder and all its contents

How to remove a folder and all its contents

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
9 Posts 6 Posters 1 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.
  • P Offline
    P Offline
    piul
    wrote on last edited by
    #1

    Hi to all, I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents. I've tried to use Directory.Remove() but for some reason my compiler does not recognise System as a valid namespace. Thanks for the help

    C V M D T 5 Replies Last reply
    0
    • P piul

      Hi to all, I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents. I've tried to use Directory.Remove() but for some reason my compiler does not recognise System as a valid namespace. Thanks for the help

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

      Are you sure that is a Visual C++ / MFC question? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      P 1 Reply Last reply
      0
      • C CPallini

        Are you sure that is a Visual C++ / MFC question? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        P Offline
        P Offline
        piul
        wrote on last edited by
        #3

        :confused: Well... I would thought so, as I want to do it programmatically in my C++ application. Am I wrong?

        C 1 Reply Last reply
        0
        • P piul

          :confused: Well... I would thought so, as I want to do it programmatically in my C++ application. Am I wrong?

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

          System namespace belongs to the .NET Framework. See [^]. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          P 1 Reply Last reply
          0
          • P piul

            Hi to all, I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents. I've tried to use Directory.Remove() but for some reason my compiler does not recognise System as a valid namespace. Thanks for the help

            V Offline
            V Offline
            vijay_aroli
            wrote on last edited by
            #5

            You can delete any directory using RemoveDirectory() function, provided that the directory which is being deleted is empty. So, you will first have to delete all the files of the directory (by using DeleteFile() function) and then use RemoveDirectory() to delete it.

            Regards, Vijay.

            1 Reply Last reply
            0
            • C CPallini

              System namespace belongs to the .NET Framework. See [^]. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              P Offline
              P Offline
              piul
              wrote on last edited by
              #6

              Ok, I didn't know that, sorry.

              1 Reply Last reply
              0
              • P piul

                Hi to all, I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents. I've tried to use Directory.Remove() but for some reason my compiler does not recognise System as a valid namespace. Thanks for the help

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

                You could try this: http://bobmoore.mvps.org/Win32/w32tip28.htm[^]

                1 Reply Last reply
                0
                • P piul

                  Hi to all, I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents. I've tried to use Directory.Remove() but for some reason my compiler does not recognise System as a valid namespace. Thanks for the help

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

                  piul wrote:

                  I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents.

                  Use SHFileOperation().

                  "Love people and use things, not love things and use people." - Unknown

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  1 Reply Last reply
                  0
                  • P piul

                    Hi to all, I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents. I've tried to use Directory.Remove() but for some reason my compiler does not recognise System as a valid namespace. Thanks for the help

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #9

                    using SYSTEM.IO; can help

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                    Never mind - my own stupidity is the source of every "problem" - Mixture

                    cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                    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