Results 1 to 20 of 20

Thread: [SOLVED]Search Text File

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Resolved [SOLVED]Search Text File

    Hi, i'm making a little programme that is working absoluetly fine at the moment. It simply searches for certain files. Now I would like to know how to make it search for the files in a text file. So for example my text file looks like this:

    file1.zip
    file2.zip

    How can i get VB to read that so I can search for it?

    Thanks in advance!
    Last edited by BefunMunkToloGen; Apr 6th, 2005 at 05:16 PM.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Search Text File

    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Search Text File

    This should help with basic text files,

    http://www.vbforums.com/showthread.php?p=1895348

  4. #4
    Junior Member
    Join Date
    Feb 2005
    Location
    Minneapolis
    Posts
    23

    Re: Search Text File

    I seems to me that you mean "search the 'zip' file" for a certain file name you specify.

    If that is the case you need to get a zip control or zip dll that will allow you to call properties and methods for zip compressed files. Do a google search on zip control or zip dll and you will find lots. Here are a couple of examples:

    http://www.abale.com/
    http://www.bigspeed.net/index.php?page=bszipdll

    I have used the second one and it works pretty well. Most are not free. Most will have a method that will list all the files in a zip without actually doing the extraction. You can then search the structure returned for the file you are after.

    Hope that helps.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Search Text File

    Thanks for the replies. I'm not looking for files inside zip files im just looking for file names, they are actually .pbo files. I will check them links out. Cheers

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Search Text File

    None of them seem to help. Say this is my text file:

    1234.zip
    2423.pbo
    hello.txt
    thanks.exe

    I want to say line 1 of text file = line1
    Line 2 (2434.pbo) of text file = line2


    Search Line1
    Search Line2
    Search Line3

    Etc? lol, hard to explain. Hope you understand.

    Thanks

  7. #7
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Search Text File

    open your file and use the Line Input statement.
    VB Code:
    1. Dim aline As String
    2.  
    3. Open "C:\yourfile.txt" For Input As #1
    4.  Do While Not EOF(1)
    5.   Line Input #1, aline
    6.   'do whatever with the string aline
    7.  Loop
    8. Close #1

    casey.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Search Text File

    Thanks Casey! Thats exactly what i needed!

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: [RESOLVED] - Search Text File

    How can i do it to search more lines then one?

  10. #10
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: [RESOLVED] - Search Text File

    that will search each line one at a time.

    casey.

  11. #11
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [RESOLVED] - Search Text File

    I think you need to explain it better. If this is solved (which I don't think it is since the bottom post has a new question on it), please state it better. I personally don't understand.

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: [RESOLVED] - Search Text File

    Heres what I have

    VB Code:
    1. Private Sub tSearch_Timer()
    2. txt.Caption = "Searching for ukf_infantry.pbo..."
    3. Dim CSIDL As Long
    4. Dim DefPath As String
    5. DefPath = GetFolderPath(CSIDL_PROGRAM_FILES)
    6. DefFold = DefPath & "\Codemasters\OperationFlashpoint\@ECP\Addons\"
    7. Dim tempStr As String, Ret As Long
    8. tempStr = String(MAX_PATH, 0)
    9. Ret = SearchTreeForFile(DefFold, HOWD I PUT OUTPUT HERE??, tempStr)
    10. If Ret <> 0 Then
    11. With lst
    12. .AddItem HOWD I PUT OUTPUT HERE?? & " - " & DefFold & "ukf_infantry"
    13. End With
    14. Else
    15. End If
    16. tSearch.Enabled = False
    17. End Sub
    18.  
    19. Private Sub txtSearch_Click()
    20. txtSearch.Enabled = False
    21. Open (App.Path & "\flz.22") For Input As #1
    22.  Do While Not EOF(1)
    23.   Line Input #1, TLine
    24.  Loop
    25. Close #1
    26. defFol.Enabled = False
    27. tSearch.Enabled = True
    28. End Sub

    I want it to search for the first line, third line, fifth line etc of what is in the text file. So basically, can i turn each line found from the text file into a global string?

  13. #13
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: [RESOLVED] - Search Text File

    as you are going through the loop, have a counter keeping record of which line you are on then check if the number is odd, if it is then add it to the string.

    do you want an array or one long string of what you find ?

    casey.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Search Text File

    Say line one of the text is EXAMPLE i want to make that line into a string so i can do something like

    Search examplestringname.

    ?? lol

  15. #15
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Search Text File

    correct me if i am wrong, are you searching the textfile and if the line(filename) is a .pbo extension then add it to a listbox ?, if so then try this.
    VB Code:
    1. Dim TLine As String
    2.  
    3. Open (App.Path & "\flz.22") For Input As #1
    4.  Do While Not EOF(1)
    5.   Line Input #1, TLine
    6.    If Right$(TLine, 4) = ".pbo" Then
    7.     List1.AddItem TLine
    8.    End If
    9.  Loop
    10. Close #1

    casey.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Search Text File

    No. Heres the situation. I need a programme to find out if a person has files missing in a certain folder. So if they don't have that file then it's added to the list. All the files are .pbo.

  17. #17
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Search Text File

    if the certain folder is the same one all the time then use the Dir() function aswell to check if it exists, if it doesnt then add the item.
    VB Code:
    1. Dim TLine As String
    2.  
    3. Open (App.Path & "\flz.22") For Input As #1
    4.  Do While Not EOF(1)
    5.   Line Input #1, TLine
    6.    If Dir$("C:\thepath\tothe\folder\" & TLine) = "" Then
    7.     List1.AddItem TLine
    8.    End If
    9.  Loop
    10. Close #1

    is this it or am i just confused

    casey.

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Search Text File

    I want to search a directory for files using the lines in the text file. lol im confusing myself.

  19. #19
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Search Text File

    well you say your textfile as filenames so that code is taking each line which is a filename then adding it to the end of the string to the full folder path and checking if it exists.

    If Dir$("C:\thepath\tothe\folder\" & TLine) = "" Then


    is the folder where the files should be always the same ?

    casey.

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Search Text File

    I see, it's late. Thats brilliant thanks a load

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