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. Visual Basic
  4. How do I delete all files in a folder?

How do I delete all files in a folder?

Scheduled Pinned Locked Moved Visual Basic
question
7 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.
  • C Offline
    C Offline
    Code Crapper
    wrote on last edited by
    #1

    Hey everyone, well the title says it all. How do I delete all files in a folder? e.g. TEMP folder PS: How would I display the results in a textbox of what is in that folder before i delete it? ( then i click a button to comfirm deletion)

    C J T 3 Replies Last reply
    0
    • C Code Crapper

      Hey everyone, well the title says it all. How do I delete all files in a folder? e.g. TEMP folder PS: How would I display the results in a textbox of what is in that folder before i delete it? ( then i click a button to comfirm deletion)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Sadly, the answer is 'one at a time'.  Directory.GetFiles will tell you the files, then you delete them one at a time.

      SLRGrant wrote:

      PS: How would I display the results in a textbox of what is in that folder before i delete it?

      Same way, show them what Directory.GetFiles returns, you can make that array of strings the datasource of a list control.

      Christian Graus - C++ MVP

      C 1 Reply Last reply
      0
      • C Code Crapper

        Hey everyone, well the title says it all. How do I delete all files in a folder? e.g. TEMP folder PS: How would I display the results in a textbox of what is in that folder before i delete it? ( then i click a button to comfirm deletion)

        J Offline
        J Offline
        Janani Divya
        wrote on last edited by
        #3

        SLRGrant wrote:

        How would I display the results in a textbox of what is in that folder

        http://www.codeproject.com/dotnet/folderwatcher.asp[^]

        Janani

        1 Reply Last reply
        0
        • C Christian Graus

          Sadly, the answer is 'one at a time'.  Directory.GetFiles will tell you the files, then you delete them one at a time.

          SLRGrant wrote:

          PS: How would I display the results in a textbox of what is in that folder before i delete it?

          Same way, show them what Directory.GetFiles returns, you can make that array of strings the datasource of a list control.

          Christian Graus - C++ MVP

          C Offline
          C Offline
          Code Crapper
          wrote on last edited by
          #4

          Christian Graus wrote:

          Sadly, the answer is 'one at a time'. Directory.GetFiles will tell you the files, then you delete them one at a time.

          Does that mean that I couldnt create a program that could clean the computer like CCleaner for example? :sigh:

          C 1 Reply Last reply
          0
          • C Code Crapper

            Christian Graus wrote:

            Sadly, the answer is 'one at a time'. Directory.GetFiles will tell you the files, then you delete them one at a time.

            Does that mean that I couldnt create a program that could clean the computer like CCleaner for example? :sigh:

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            No, of course not.  Why would it mean that ?

            Christian Graus - C++ MVP

            1 Reply Last reply
            0
            • C Code Crapper

              Hey everyone, well the title says it all. How do I delete all files in a folder? e.g. TEMP folder PS: How would I display the results in a textbox of what is in that folder before i delete it? ( then i click a button to comfirm deletion)

              T Offline
              T Offline
              The ANZAC
              wrote on last edited by
              #6

              If you want to delete all the files in a folder, the best approach would be to use a for/next statement. use a listbox for your display as oppose to a textbox. Dim di as new system.io.directoryinfo = "your directory" '(1) Dim fi as system.io.fileinfo for each fi in di.getfiles'(5) '(4) listbox1.items.add(fi.filename) fi.delete '(2) (3) '(4) next Note: (1) You could use a folder browser dialog to establish the folder or for the user to establish the folder (2) When testing, have a test folder filled with copies files or something. (3) If you wished to display first then give the option of deleting, you could put a similar for/next statement under a button's click action or something and only have delete option. (4) You could have an if statement here for certain paremeters (5) In the brackets after getfiles, you can specify file type

              Posted by The ANZAC

              C 1 Reply Last reply
              0
              • T The ANZAC

                If you want to delete all the files in a folder, the best approach would be to use a for/next statement. use a listbox for your display as oppose to a textbox. Dim di as new system.io.directoryinfo = "your directory" '(1) Dim fi as system.io.fileinfo for each fi in di.getfiles'(5) '(4) listbox1.items.add(fi.filename) fi.delete '(2) (3) '(4) next Note: (1) You could use a folder browser dialog to establish the folder or for the user to establish the folder (2) When testing, have a test folder filled with copies files or something. (3) If you wished to display first then give the option of deleting, you could put a similar for/next statement under a button's click action or something and only have delete option. (4) You could have an if statement here for certain paremeters (5) In the brackets after getfiles, you can specify file type

                Posted by The ANZAC

                C Offline
                C Offline
                Code Crapper
                wrote on last edited by
                #7

                Cool, well thanks guys for all your help, I will fiddle about with the code and see what the result is ;P

                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