5 Replies - 539 Views - Last Post: 21 January 2013 - 01:53 PM Rate Topic: -----

#1 badcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 13

CheckedListBox items existing in Folder

Posted 17 January 2013 - 08:04 PM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: CheckedListBox items existing in Folder

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

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.
Was This Post Helpful? 0
  • +
  • -

#3 badcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 13

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.
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

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.
Was This Post Helpful? 0
  • +
  • -

#5 badcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 13

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?
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1