Results 1 to 4 of 4

Thread: [RESOLVED] Dynamic folder serarch when searching for files

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    41

    Resolved [RESOLVED] Dynamic folder serarch when searching for files

    I have a file search that I want the user to select the folder they are searching the file in
    At the moment I have

    If Check.Text = "Correct" Then

    If My.Computer.FileSystem.FileExists("C:\Systems\file.txt") Then
    1CheckBox.Checked() = True
    Else
    1CheckBox.Checked = False

    End If

    However this check will be used for various files and its not usable if the FileExists directory stays the same ie searching the same folder and file for different records. I have a FolderBrowseDialog that I want the user to select the folder first in where to search and then within this chosen folder the static file will be checked. I have this as my folderbrowsedialog:

    Dim Browser As New FolderBrowserDialog
    Browser.Description = "Please select ."
    Browser.ShowNewFolderButton = False
    Browser.RootFolder = "c:\"
    Browser.SelectedPath = "c:\windows"
    If Browser.ShowDialog = Windows.Forms.DialogResult.OK Then
    Me.text.Text = Browser.SelectedPath
    End If

    I tried adding in this code to the actual file check to encoporated the dynamic folder search but its bringing up errors and not working, I have this:

    Dim path As String = "Browser"
    Dim f As ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles("test.xlsx")
    If My.Computer.FileSystem.FileExists("test.xlsx") Then
    Box.Checked() = True


    Any help would be amazing as my VB knowledge is not the strongest

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Dynamic folder serarch when searching for files

    So, basically you want the user to select a folder and then test whether a file with a specific name exists in that folder, correct? If so then use the FolderBrowserDialog and get the folder path as a String from its SelectedPath property. Use My.Computer.FileSystem.CombinePath to join that folder path with your file name. You can then pass that result, which is another String, to the My.Computer.FileSystem.FileExists.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    41

    Re: Dynamic folder serarch when searching for files

    Thanks for the quick reply I will try that

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    41

    Re: Dynamic folder serarch when searching for files

    I got it to work, thank you so much!!!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width