In my program I have a CheckedListBox where you input file names and when you use the search button, the program is supposed to go through each item in the list and check to see if that file exists within the folder. What would I need to use to add the files within the selected folder to a string to compare with the items in the list?
CheckedListBox items existing in Folder
Page 1 of 15 Replies - 237 Views - Last Post: 21 January 2013 - 01:53 PM
Replies To: CheckedListBox items existing in Folder
#2
Re: CheckedListBox items existing in Folder
Posted 17 January 2013 - 08:27 PM
That does not make sense, why would have to search and see if it exists? Why wouldn't you load files from a directory into the CLB? If there are changing in the background you can always check if a file exists before processing it. Tell us more about the functioning of this program.
#3
Re: CheckedListBox items existing in Folder
Posted 17 January 2013 - 08:31 PM
The function of the program is that the user enters in a list of files which are added to the list box. When the user then selects a folder to search through, the program is supposed to read the file names within the selected folder and if the files in the list exist within the folder, it checks the item.
#4
Re: CheckedListBox items existing in Folder
Posted 17 January 2013 - 09:29 PM
So it's a matter of creating a list of the files in the directory and see if it contains a select file by user. You can look into directoryInfo and it's GetFiles method to create the list to compare to.
#5
Re: CheckedListBox items existing in Folder
Posted 21 January 2013 - 09:26 AM
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim Files As New FileStream("FileDirectories.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim FilesWriter As New StreamWriter(Files)
Dim di As New IO.DirectoryInfo(fbdDirectory.ToString)
Dim DirectoryFiles As FileInfo() = di.GetFiles(Path, SearchOption.AllDirectories)
FilesWriter.WriteLine(DirectoryFiles.ToString)
Dim FilesReader As New StreamReader(Files)
Me.txtFileNames.Text = FilesReader.ReadToEnd.ToString
Dim FileListings As String = FilesReader.ReadToEnd.ToString
For Counter As Integer = 0 To clbFiles.Items.Count - 1
If clbFiles.Items(Counter).IndexOf(FileListings) <> -1 Then
clbFiles.SetItemChecked(Counter, True)
End If
Next
FilesWriter.Close()
FilesReader.Close()
Files.Close()
End Sub
I get an error on the
Dim DirectoryFiles As FileInfo() = di.GetFiles(Path, SearchOption.AllDirectories)line because of an error saying that path2 cannot be a drive or UNC name, is there a way to get past this?
#6
Re: CheckedListBox items existing in Folder
Posted 21 January 2013 - 01:53 PM
C: is a drive and C:/ is the root directory for this drive. DriveInfo("C:").RootDirectory is another option.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|