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. Search and delete files

Search and delete files

Scheduled Pinned Locked Moved Visual Basic
css
7 Posts 6 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.
  • H Offline
    H Offline
    hendrikbez
    wrote on last edited by
    #1

    I did do a search but cannot find any sample. I am looking for a sample like this. 1. Search c: for say *.pdf files. 2. Show files in a grid with name of file, size, path. 3. Then I can delete all or just choose the files I want to delete.

    A D L 3 Replies Last reply
    0
    • H hendrikbez

      I did do a search but cannot find any sample. I am looking for a sample like this. 1. Search c: for say *.pdf files. 2. Show files in a grid with name of file, size, path. 3. Then I can delete all or just choose the files I want to delete.

      A Offline
      A Offline
      Andy_L_J
      wrote on last edited by
      #2

      Break the problem down into smaller problems: 1: get a list of files: http://www.developerfusion.com/code/3681/list-files-in-a-directory/[^] 2: Select the file you want in the list or datagrid (google will help you) 3: Perform the delete file on the selected record. (again google will do most of this for you).

      I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

      1 Reply Last reply
      0
      • H hendrikbez

        I did do a search but cannot find any sample. I am looking for a sample like this. 1. Search c: for say *.pdf files. 2. Show files in a grid with name of file, size, path. 3. Then I can delete all or just choose the files I want to delete.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You're never going to find an app that does all of this. You will however find examples for each of those steps. It's up to you to write the code to stitch all of those steps together in a single app.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        1 Reply Last reply
        0
        • H hendrikbez

          I did do a search but cannot find any sample. I am looking for a sample like this. 1. Search c: for say *.pdf files. 2. Show files in a grid with name of file, size, path. 3. Then I can delete all or just choose the files I want to delete.

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

          Hello, you can do something like this and then using a foreach loop, or list them on datagird.

          Dim strFileSize As String = ""
          Dim di As New IO.DirectoryInfo("C:\path")
          Dim aryFi As IO.FileInfo() = di.GetFiles("*.pdf")
          Dim fi As IO.FileInfo

              For Each fi In aryFi
                  strFileSize = (Math.Round(fi.Length / 1024)).ToString()
                  
                  'yourdatagridcell("File Name: {0}", fi.Name)
                  'yourdatagridcell("File Full Name: {0}", fi.FullName)
                  'yourdatagridcell("File Size (KB): {0}", strFileSize)
                  'yourdatagridcell("File Extension: {0}", fi.Extension)
                  'yourdatagridcell("Last Accessed: {0}", fi.LastAccessTime)
                  'yourdatagridcell("Read Only: {0}", (fi.Attributes.ReadOnly = True).ToString)
              Next
          

          Regards

          Carmelo La Monica

          H 1 Reply Last reply
          0
          • L Lost User

            Hello, you can do something like this and then using a foreach loop, or list them on datagird.

            Dim strFileSize As String = ""
            Dim di As New IO.DirectoryInfo("C:\path")
            Dim aryFi As IO.FileInfo() = di.GetFiles("*.pdf")
            Dim fi As IO.FileInfo

                For Each fi In aryFi
                    strFileSize = (Math.Round(fi.Length / 1024)).ToString()
                    
                    'yourdatagridcell("File Name: {0}", fi.Name)
                    'yourdatagridcell("File Full Name: {0}", fi.FullName)
                    'yourdatagridcell("File Size (KB): {0}", strFileSize)
                    'yourdatagridcell("File Extension: {0}", fi.Extension)
                    'yourdatagridcell("Last Accessed: {0}", fi.LastAccessTime)
                    'yourdatagridcell("Read Only: {0}", (fi.Attributes.ReadOnly = True).ToString)
                Next
            

            Regards

            Carmelo La Monica

            H Offline
            H Offline
            hendrikbez
            wrote on last edited by
            #5

            Thank you I am using this code to get files, but I can not get it to search for all files on C: drive. How can I get it to show all files Like *.pdf of the dirve in the list box

            Imports System.IO
            Imports System
            Imports System.Drawing
            Imports System.Windows.Forms

            Public Class SearchAvi

            Private Sub BtnGetAviFiles\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetAviFiles.Click
            
                Dim dir1 As New IO.DirectoryInfo("c:")
                Dim dir2 As IO.FileInfo() = dir1.GetFiles()
                Dim files1 As IO.FileInfo
            
                For Each files1 In dir2
                    FrmListBox.Items.Add(files1)
                Next
            
            End Sub
            
            T 1 Reply Last reply
            0
            • H hendrikbez

              Thank you I am using this code to get files, but I can not get it to search for all files on C: drive. How can I get it to show all files Like *.pdf of the dirve in the list box

              Imports System.IO
              Imports System
              Imports System.Drawing
              Imports System.Windows.Forms

              Public Class SearchAvi

              Private Sub BtnGetAviFiles\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetAviFiles.Click
              
                  Dim dir1 As New IO.DirectoryInfo("c:")
                  Dim dir2 As IO.FileInfo() = dir1.GetFiles()
                  Dim files1 As IO.FileInfo
              
                  For Each files1 In dir2
                      FrmListBox.Items.Add(files1)
                  Next
              
              End Sub
              
              T Offline
              T Offline
              Thomas Krojer
              wrote on last edited by
              #6

              You also have search all SUBDIRECTORIES of a given Startpoint. You should write a function getting all files and directories, and then you can call this function recursive (calling it for each subdirectory with an new startdir).

              I cannot remember: What did I before google?

              M 1 Reply Last reply
              0
              • T Thomas Krojer

                You also have search all SUBDIRECTORIES of a given Startpoint. You should write a function getting all files and directories, and then you can call this function recursive (calling it for each subdirectory with an new startdir).

                I cannot remember: What did I before google?

                M Offline
                M Offline
                MicroVirus
                wrote on last edited by
                #7

                I suggest using a LIFO stack (Stack collection in .NET) in stead of recursing. I've done this a couple of times now and the basic algorithm works like:

                Push start directory onto stack
                loop while stack is non-empty
                pop last element off the stack (directory)
                do action on element (here: find all *.pdf files)
                list all subdirectories and for each push full subdirectory path on the stack
                end loop

                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