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