Results 1 to 12 of 12

Thread: file system search program

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    790

    file system search program

    I am trying to create a program that does a file system search.
    I have a form that has three textboxes and a data grid and a search button.
    One text box has the date and another has the month and the thrid contains the year. Upon clicking the search button a data grid gets populated on the form via the search that shows the file information which is in a pdf format shoudla user enter in a year that matches it pulls up all the files under that files and shows them in the grid..if they enter a month it shows all information under that month. Bu that's about all..can anyone help me figure out what I might need to do next exactly ? Or perhaps someone has an example handy that gives me an idea of what needs to be done ?

    Now I remembered from last week that I would need the following in a subroutine:
    Dim objStream As New FileStream(" file path", FileMode.Open)
    Dim objReader As New StreamReader(objStream)
    Dim strBuffer As String
    strBuffer = objReader.ReadToEnd
    objReader.Close()
    objStream.Close()
    MsgBox(strBuffer)

  2. #2
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: file system search program

    where are you making the search? in a specific folder or in all the available drives? Does the search need to search the subfolders as well?
    When you find a file that matches the pdf extension, you need a fileInfo object to retrieve the date information about the file and then extract the value that you are looking for to compare it to the user input

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    790

    Re: file system search program

    Quote Originally Posted by talkro
    where are you making the search? in a specific folder or in all the available drives? Does the search need to search the subfolders as well?
    When you find a file that matches the pdf extension, you need a fileInfo object to retrieve the date information about the file and then extract the value that you are looking for to compare it to the user input

    I am searching in a specific folder where all the pdfs are contained. There are no subfolders. A fileInfo object ?Would this need to be incorporated in the code I have above ? How would this be stated in code format exactly ? For example would this be contained the btnSearch click event ?

  4. #4
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: file system search program

    this will be contained in the btnSearch and you can check this link for more info

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    790

    Re: file system search program

    Quote Originally Posted by talkro
    this will be contained in the btnSearch and you can check this link for more info

    Ok. I looked back in the threads here and found this code.

    Code:
    1.	Private Sub RecFileSearch(ByVal dir As String)
    2.	        Try
    3.	            Dim di As New DirectoryInfo(dir)
    4.	            Dim fi() As FileInfo
    5.	            fi = di.GetFiles
    6.	            For X As Integer = 0 To fi.Length - 1
    7.	                ListBox1.Items.Add(fi(X).FullName) 'Your code for each file goes here.
    8.	            Next
    9.	            Dim DirectoryArray() As DirectoryInfo
    10.	            DirectoryArray = di.GetDirectories
    11.	            If DirectoryArray.Length > 0 Then
    12.	                For i As Integer = 0 To DirectoryArray.Length - 1
    13.	                    RecFileSearch(DirectoryArray(i).FullName)
    14.	                Next
    15.	            End If
    16.	        Catch ex As FileNotFoundException
    17.	            'Ignore any File not found - sometimes Temp files show in the DirectoryInfo/FileInfo
    18.	            ' then are gone by the time the loop tries to get info on them.
    19.	        Catch ex As Exception
    20.	            MsgBox("There was an error:" + ex.ToString) 'Ordinarily "System Volume Information" will throw this exception as an Access Exception.. You can handle that how you want.
    21.	 
    22.	        End Try
    23.	 
    24.	    End Sub

  6. #6
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: file system search program

    in your case, you only need to use the first loop and instead of adding to the listbox directly, you first use the members of the fileInfo class to find if the file matches the criteria and then you add the needed info in you viewer

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    790

    Re: file system search program

    Quote Originally Posted by talkro
    in your case, you only need to use the first loop and instead of adding to the listbox directly, you first use the members of the fileInfo class to find if the file matches the criteria and then you add the needed info in you viewer
    I must admit you have me confused with your last statement here.
    Wouldn't I use the following to find what I needed ? This is a snippet from some code for my datagrid.

    Code:
    <%@ Import Namespace="System.IO" %>
    <script language="VB" runat="server">
      Sub Page_Load(sender as Object, e as EventArgs)
        Dim dirInfo as New DirectoryInfo(Server.MapPath(""))
        
        articleList.DataSource = dirInfo.GetFiles("*.aspx")
        articleList.DataBind()
      End Sub
    </script>
    The second line in boldface grabs all of the files with the .aspx extensions. And then binds this information to the datagrid named articlelist.

  8. #8
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: file system search program

    i though you already had the path where to search and that you are looking for some files that either match the year or the month enter by the user?
    Otherwise your are write. my bad

  9. #9
    Hyperactive Member ProphetBeal's Avatar
    Join Date
    Aug 2006
    Location
    New York
    Posts
    424

    Re: file system search program

    I've have made a File search app and posted the code here http://www.vbforums.com/showthread.php?t=455148. This should help with some of your questions.

    Helpful Links:
    VB 6 - How to get the "Key" Value in a collection
    VB.NET - File Search Utility || VB.NET - How to compare 2 directories || VB.NET - How to trust a network share
    VB.NET - Create Excel Spreadsheet From Array || VB.NET - Example Code & Hints you may not know
    VB.NET - Save JPEG with a certain quality (image compression) || VB.NET - DragDrop Files, Emails, and Email Attachments

    Please post some of the code you need help with (it makes it easier to help you)
    If your problem has been solved then please mark the thread [RESOLVED].
    Don't forget to Rate this post

    "Pinky, you give a whole new meaning to the phrase, 'counter-intelligence'."-The Brain-

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    790

    Re: file system search program

    Quote Originally Posted by talkro
    i though you already had the path where to search and that you are looking for some files that either match the year or the month enter by the user?
    Otherwise your are write. my bad
    Hey.I just didn't write in the filepath I was using in the line of code. So it isn't your bad quite yet.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    790

    Re: file system search program

    Quote Originally Posted by ProphetBeal
    I've have made a File search app and posted the code here http://www.vbforums.com/showthread.php?t=455148. This should help with some of your questions.
    I should have put this in the ASP.net forum as this will turn out to be a web application so I wonder if the same that you have here applies.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    790

    Re: file system search program

    Ok. I tested my code in the page load event of the application to see if the datagrid woudl grab everything in the file folder and it did.
    Now I need to put this logic in my btn Search and then have the program anticipate what file from the folder will be pulled based on the date or month or year entered and then the Search button clicked. I might have to filter my results from a data table.

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