Home All Groups Group Topic Archive Search About

Beginner needs help with text files

Author
7 Oct 2005 4:19 PM
Dave S
I had posted this in comp.lang.visual.basic and haven't recieved a reply
    (to be fair it's only been one day), but then came across this group and
there is much more activity here..
My apologies for cross posting(?) .

Hello all,
Hope this is the correct group for this question.
I couldn't find a vb beginners group.
I am getting overwhelmed and need some help.
I did this very easily in a batch file (only three lines), but DOS is too
limited and the use of the batch is presenting other problems (file is
compressed so I get garbage characters in the output file which I can't
edit).
I also wanted some other functionality added and decided to try VB6.

Problem -  (Totally lost and frustrated)
    How do I search all files with a given extension (ex. *.zip) for text
inside
those files and output those lines (strings) to a text file?
I need to be able to use wildcards, so from what I read the use of the File
System Object is not going to help me.
The files are compressed (don't know if that matters).
The text lines (strings) in the files I am looking for would be something
like *.bspPK(trailing garbage characters)

Any help will be much appreciated.
Thank you

Author
7 Oct 2005 5:14 PM
Matt Williamson
Dave-

You'll want to use Dir() in a loop to search for all zip files. Once you
have a valid file, you open it in either text or binary mode and loop
through the file searching for your text. You then open another file for
output and write the lines to it. If you're going to be doing this with zip
files though, do you need to extract the data first and search the
individual files? If so I can tell you how to do that too. I've done both
recently but won't go into it if it isn't necessary.

In the meantime, take a look at these

http://msdn.microsoft.com/library/en-us/vbenlr98/html/vafctDir.asp?frame=true

http://msdn.microsoft.com/library/en-us/vbenlr98/html/vastmopen.asp


-HTH

Matt


Show quoteHide quote
"Dave S" <h***@thestore.com> wrote in message
news:zex1f.9536$Ge5.9496@fe10.lga...
>I had posted this in comp.lang.visual.basic and haven't recieved a reply
>    (to be fair it's only been one day), but then came across this group
> and there is much more activity here..
> My apologies for cross posting(?) .
>
> Hello all,
> Hope this is the correct group for this question.
> I couldn't find a vb beginners group.
> I am getting overwhelmed and need some help.
> I did this very easily in a batch file (only three lines), but DOS is too
> limited and the use of the batch is presenting other problems (file is
> compressed so I get garbage characters in the output file which I can't
> edit).
> I also wanted some other functionality added and decided to try VB6.
>
> Problem -  (Totally lost and frustrated)
>    How do I search all files with a given extension (ex. *.zip) for text
> inside
> those files and output those lines (strings) to a text file?
> I need to be able to use wildcards, so from what I read the use of the
> File
> System Object is not going to help me.
> The files are compressed (don't know if that matters).
> The text lines (strings) in the files I am looking for would be something
> like *.bspPK(trailing garbage characters)
>
> Any help will be much appreciated.
> Thank you
>
>
>
Author
7 Oct 2005 7:14 PM
Dave S
Thanks for your quick reply Matt.

Before I go any further I just want to make sure I understand.
In Visual Basic I can NOT do something as simple as what I would do in a dos
batch file?

     Example:
     find /i ".bsp" "*.zip" > "garbagefile.txt"
     findstr /r ".bspPK*" "garbagefile.txt" > "bsplist.txt"
    del "garbagefile.txt"

As I am a very green beginner it will take me some time to read and
understand how to implement a do loop so please be patient if I don't post
back to quickly.
I also am not sure yet how to perform a search within the zip file or any
file for that matter.
Everything I am reading pertains to finding directories or files not finding
text inside a file.

You asked; If I needed to extract the data from within the "zip"?  You meant
to actually perform the extract function?
    No, I just need to search within the zip to find the strings that
contain " .bspPK " then output those strings to a text file.

And also in understanding what you stated;  I need to actually open each zip
file to do the search for the string?
Will that become a problem with many zip files?
I have at minimum 50 to search thru. and possibly a few hundred.
To clarify:
My files are not "actually" zip files.
They are PK3 files, which are a compressed file.
I don't think that will matter though.
Author
7 Oct 2005 7:43 PM
Larry Serflaten
"Dave S" <h***@thestore.com> wrote in
> Thanks for your quick reply Matt.
>
> Before I go any further I just want to make sure I understand.
> In Visual Basic I can NOT do something as simple as what I would do in a dos
> batch file?
>
>      Example:
>      find /i ".bsp" "*.zip" > "garbagefile.txt"
>      findstr /r ".bspPK*" "garbagefile.txt" > "bsplist.txt"
>     del "garbagefile.txt"
>

What more do you want to do?  You could have DOS do what it already
does, and then use VB to read only the output file.  For an example, create
a batch file from the above commands, and call it from VB using Shell.

Shell "MyPath/MyBatchFile.bat", vbHide

You could then read in that bspList.txt file into a textbox, or whatever....

LFS
Author
7 Oct 2005 8:33 PM
Dave S
Hi Larry,
I actually did implement the batch file in a previous test.
I had the data from the bsplist.txt going to a textbox.
This allowed me to directly edit the textbox and remove the extra garbage
data in the strings and output the "cleaned strings" to a new and final
file.
This worked great.
However, the problem I ran across is in having the user run the program from
any directory they want.
The batch file needs to be put in the directory its going to search from.
I didn't want to have the user add and remove extra files from one directory
to another.
I figured if I do away with the batch and have VB do the searching I can
have the user set the path from an Inputbox.

I'm guessing I am getting in way over my head.
I have no programing experience, and it took me weeks to figure out how to
get the batch file to work.
Thought I could make life a bit easier with VB, but it doesn't seem to be
the case.

In case you may be wondering what the main scope of this is:
I admin a bunch of gaming servers.
The games use .PK3 files (pack files - compressed).
Within some of these PK3's are the names of the maps (.bsp) the games run
on.
Each server uses a map rotation file to cycle through the maps.
New maps are constantly being added to the servers (keeps things
interesting).
It takes me forever to manually open each pk3 and find the map name to add
to the map rotation file.
If there is a typo in the map name it crashes the server.
Unfortunately I can't copy and paste from within a compressed file
(eliminating any typos).
I figured if I could have the computer spit out a file of these map names
(*.bsp's) it would save me a lot of time.
If I was the only one doing this I wouldn't mind moving the batch file, but
there are others involved.
Also, some servers are run for tournament matches and they can not have
extra files in them other than the map files as per the rules of the
tournament.
So the batch files would constantly have to be removed from the server prior
to any matches being held on them.
This would be a problem if the batch was left in by mistake.

Thanks for replying.
Dave S
Author
8 Oct 2005 2:48 AM
Larry Serflaten
Show quote Hide quote
"Dave S" <h***@thestore.com> wrote
> I actually did implement the batch file in a previous test.
> I had the data from the bsplist.txt going to a textbox.
> This allowed me to directly edit the textbox and remove the extra garbage
> data in the strings and output the "cleaned strings" to a new and final
> file.
> This worked great.
> However, the problem I ran across is in having the user run the program from
> any directory they want.
> The batch file needs to be put in the directory its going to search from.
> I didn't want to have the user add and remove extra files from one directory
> to another.
> I figured if I do away with the batch and have VB do the searching I can
> have the user set the path from an Inputbox.

How about you write the code to tell VB to create the batch file where it needs
to be, then use it, then delete it when your done?

To tell VB to create the batch file is pretty simple:
(Assume PATH is the directory path the user is looking in)

FF = FreeFile
Open Path & "\TempBat.bat" For Output As FF
Print #FF, "find /i "".bsp"" ""*.zip"" > ""garbagefile.txt"""

Print #FF, "findstr /r "".bspPK*"" ""garbagefile.txt"" > ""bsplist.txt"""
Print #FF, "del ""garbagefile.txt"""
Close FF
Shell Path & "\TempBat.bat", vbHide

Note that Print requires two quotes to be used where you want one quote
printed to the file (The quote has to be escaped inside a string).

Then go looking for your bsplist.txt file (with a few retries in case it takes
a while) and when you find it, and have loaded it into your textbox, it will
then be save to delete the batch file you created.  The user gets the list
and the batch file is no longer in the directory....

LFS



Show quoteHide quote
>
> I'm guessing I am getting in way over my head.
> I have no programing experience, and it took me weeks to figure out how to
> get the batch file to work.
> Thought I could make life a bit easier with VB, but it doesn't seem to be
> the case.
>
> In case you may be wondering what the main scope of this is:
> I admin a bunch of gaming servers.
> The games use .PK3 files (pack files - compressed).
> Within some of these PK3's are the names of the maps (.bsp) the games run
> on.
> Each server uses a map rotation file to cycle through the maps.
> New maps are constantly being added to the servers (keeps things
> interesting).
> It takes me forever to manually open each pk3 and find the map name to add
> to the map rotation file.
> If there is a typo in the map name it crashes the server.
> Unfortunately I can't copy and paste from within a compressed file
> (eliminating any typos).
> I figured if I could have the computer spit out a file of these map names
> (*.bsp's) it would save me a lot of time.
> If I was the only one doing this I wouldn't mind moving the batch file, but
> there are others involved.
> Also, some servers are run for tournament matches and they can not have
> extra files in them other than the map files as per the rules of the
> tournament.
> So the batch files would constantly have to be removed from the server prior
> to any matches being held on them.
> This would be a problem if the batch was left in by mistake.
>
> Thanks for replying.
> Dave S
>
>
Author
8 Oct 2005 2:49 AM
Larry Serflaten
Just thought I'd mention, in VB the command to delete a file
is Kill (See help for its use)

LFS
Author
9 Oct 2005 9:47 PM
Dave S
Larry,
Thanks for the help with the batch file.

I ran the code and it worked fine, but for some reason it only ran the batch
file if it was in the directory that I was running the program from.
-Original code:
   Shell (path & filename), vbNormalFocus
-
If I changed the path (inputbox) it would create the batch file in the
directory but not run it.
I seemed to have found a way around it by adding another shell line and
hiding the first batch file.
-New Modified code:
   Shell (path & filename), vbHide

   Call ShellExecute(hwnd, "Open", batchpath, "", path, 1)
-
I have no idea of what I'm really doing so its just cut and pasting
different code snippets to get results and learning from that.
I also seemed to have resolved an error with the file not being found (batch
needs to finish first) by adding a msgbox.

I do have another question you may be able to help me with.
I have the batch creation being executed from Command1_click.
How can I get the users path (inputbox) to be used in other parts of my
program?
Like using that path selected from Command1_click to be used in
Command2_click , to say remove a file or do other things.
Author
10 Oct 2005 5:23 PM
Dave S
Larry,
I think I answered my last question regarding making the InputBox a
reusable variable(?).
It seems to be working so far.
I still need to write more code and attempt to use it in other parts of the
project.
Please let me know if there is something wrong with the way I am doing this.

General Declarations :
    Public userpath As String
_______________________
Function paths()
    userpath = InputBox("Enter Path")
_______________________
Private Sub Command1_Click()
    paths

Rest of Code ..............
Author
7 Oct 2005 7:52 PM
Matt Williamson
Dave-

If you're just looking for all files of a type with a certain string in the
filename, something like this will do it.

Open a new project and add a module. Remove form1

Add this to the module:

Sub Main()

Dim sFileName as string, ff as long
Dim sOutputFile as string, sPath as string

sOutputFile = "C:\Outputfile.txt"
sPath = "C:\PathOfZipFiles"

ff = Freefile 'valid free file handle
Open sOutputfile for Append as #ff
sFileName = Dir$(sPath & "\*.zip", vbDirectory) ' all zip files in a
directory
do while sFileName <> ""
    if instr(sFileName, ".bspPK") then ' contains search string
        input #ff, sFileName ' write filename to output
    end if
sFileName = Dir 'next file
loop
close #ff

End sub

Hit F8 to start debugging the program line by line and hover the mouse over
the variable names to see what's happening. You can also watch in the locals
window if you have it enabled (view | locals window)

I didn't actually test the code, but it should work or at least give you
something to start from.

HTH

-Matt


Show quoteHide quote
"Dave S" <h***@thestore.com> wrote in message
news:YNz1f.8754$dl2.7270@fe08.lga...
> Thanks for your quick reply Matt.
>
> Before I go any further I just want to make sure I understand.
> In Visual Basic I can NOT do something as simple as what I would do in a
> dos batch file?
>
>     Example:
>     find /i ".bsp" "*.zip" > "garbagefile.txt"
>     findstr /r ".bspPK*" "garbagefile.txt" > "bsplist.txt"
>    del "garbagefile.txt"
>
> As I am a very green beginner it will take me some time to read and
> understand how to implement a do loop so please be patient if I don't post
> back to quickly.
> I also am not sure yet how to perform a search within the zip file or any
> file for that matter.
> Everything I am reading pertains to finding directories or files not
> finding text inside a file.
>
> You asked; If I needed to extract the data from within the "zip"?  You
> meant to actually perform the extract function?
>    No, I just need to search within the zip to find the strings that
> contain " .bspPK " then output those strings to a text file.
>
> And also in understanding what you stated;  I need to actually open each
> zip file to do the search for the string?
> Will that become a problem with many zip files?
> I have at minimum 50 to search thru. and possibly a few hundred.
> To clarify:
> My files are not "actually" zip files.
> They are PK3 files, which are a compressed file.
> I don't think that will matter though.
>
Author
7 Oct 2005 9:53 PM
Dave S
Matt,

That seems to be exactly what I want.
The debug information is priceless and will certainly help me as I learn
(Thank you).
As a test, I set up a folder and put several files in it.
I ran your code and stepped through it as suggested.
As it cycled through the loop I could see the different zip file names come
up.
When it completed I checked the folder and the output file was there, but it
was empty. No data.
I double checked the code to see if I missed a piece, but it was as you
posted.
I thought it was because there was no form? so I tried adding a form and put
your code to a command button.
I got the same results.
What did I do wrong?
Author
10 Oct 2005 11:48 AM
Matt Williamson
Dave-

What is the actual filename of one of the files? Once I have that, I can
whip up some test files and check the code. The problem is in the InStr()
line somewhere.

HTH

Matt


Show quoteHide quote
"Dave S" <h***@thestore.com> wrote in message
news:W7C1f.1626$Hm3.696@fe09.lga...
> Matt,
>
> That seems to be exactly what I want.
> The debug information is priceless and will certainly help me as I learn
> (Thank you).
> As a test, I set up a folder and put several files in it.
> I ran your code and stepped through it as suggested.
> As it cycled through the loop I could see the different zip file names
> come up.
> When it completed I checked the folder and the output file was there, but
> it was empty. No data.
> I double checked the code to see if I missed a piece, but it was as you
> posted.
> I thought it was because there was no form? so I tried adding a form and
> put your code to a command button.
> I got the same results.
> What did I do wrong?
>
>
Author
10 Oct 2005 5:11 PM
Dave S
Hi Matt,
I wasn't sure which file name you wanted so I listed both of them.
It was easier for me to use a small zip for a test than to move the .PK3
files.
I didn't think it would matter, thinking I can change .zip for .pk3 and
change the search string from .bmp to .bspPK* or what ever I need in the
future.

File being searched for: (untitled is actual name)
    -  untitled.zip (contains 1 file - untitled.bmp)

The string i'm searching for in zip:
    -  *bmp

Generated file with found strings:
    -  Outputfile.txt

Note: when I ran the previous test I copied the above zip several times.
        The file names were same, just preceded with "Copy of" .
        So I could see the changes when I stepped through the code.
Author
10 Oct 2005 8:05 PM
Matt Williamson
Ah, that's a bit harder to do. Still fairly easy in the grand scheme of
things though. I have a routine that I found in the archives awhile back
that I modified to open a zip file and read the files within it into a
collection. I'll dig it out and post it up for you when I find it. Then,
it's just a matter of adding that in with the code I posted earlier.

HTH

Matt

Show quoteHide quote
"Dave S" <h***@thestore.com> wrote in message
news:bhx2f.38378$Xa.16826@fe12.lga...
> Hi Matt,
> I wasn't sure which file name you wanted so I listed both of them.
> It was easier for me to use a small zip for a test than to move the .PK3
> files.
> I didn't think it would matter, thinking I can change .zip for .pk3 and
> change the search string from .bmp to .bspPK* or what ever I need in the
> future.
>
> File being searched for: (untitled is actual name)
>    -  untitled.zip (contains 1 file - untitled.bmp)
>
> The string i'm searching for in zip:
>    -  *bmp
>
> Generated file with found strings:
>    -  Outputfile.txt
>
> Note: when I ran the previous test I copied the above zip several times.
>        The file names were same, just preceded with "Copy of" .
>        So I could see the changes when I stepped through the code.
>
Author
10 Oct 2005 9:28 PM
Matt Williamson
Here you go. Give this a run through. I have tested it on my machine and it
is working. You'll need to change the paths to what is appropriate on your
system, obviously. No form needed, just a single .bas module. I have some
code using the info-zip libraries to actually unzip the files too, but if
you just need to check the filenames in the .zip files, this routine is
quick and easy.


Option Explicit

Public Type typZipLocalFileHead ' 30 bytes
    zlfhSignature As Long ' 0x04034B50
    zlfhVersion As Integer
    zlfhBitFlag As Integer
    zlfhCompression As Integer
    zlfhModFileTime As Integer
    zlfhModFileData As Integer
    zlfhCRC As Long
    zlfhCompressedSize As Long
    zlfhUncompressedSize As Long
    zlfhFileNameLength As Integer
    zlfhExtraFieldLength As Integer
End Type

Sub Main()

Dim sFileName As String, ff As Long
Dim sOutputFile As String, sPath As String
Dim vFiles As Variant

sOutputFile = "C:\Outputfile.txt"
sPath = "Y:\VB\Examples"

ff = FreeFile 'valid free file handle
Open sOutputFile For Append As #ff
sFileName = Dir$(sPath & "\*.zip", vbDirectory) ' all zip files in a
directory
Do While sFileName <> ""
    For Each vFiles In ReadZip(sPath & "\" & sFileName)
        If InStr(vFiles, ".bmp") <> 0 Then ' contains search string
          Print #ff, vFiles  ' write filename to output
        End If
    Next
sFileName = Dir 'next file
Loop
Close #ff

End Sub

'ReadZip function modified from NG Posting by Mike Sutton

Public Function ReadZip(ByRef inFile As String) As Collection
    Dim FileName As String
    Dim ReadHead As typZipLocalFileHead
    Dim FNum As Integer
    Dim FileString As String
    Dim SeekSize As Long
    Dim nCnt As Long
    Dim SlashPos As Long

    Const ZipLocalFileHeadSig As Long = &H4034B50

    Set ReadZip = New Collection

   ' Make sure file exists
    If (Not FileExists(inFile)) Then Exit Function

    ' Get a free file handle and open the file
    FNum = FreeFile()
    Open inFile For Binary Access Read Lock Write As #FNum
        Do ' Read a chunk signature
            Get #FNum, , ReadHead.zlfhSignature

            ' Check for a local file header signature
            If (ReadHead.zlfhSignature = ZipLocalFileHeadSig) Then
                ' Ok, read the full structure
                Seek #FNum, Seek(FNum) - 4
                Get #FNum, , ReadHead

                With ReadHead
                    ' Get the file name
                    If (.zlfhFileNameLength) Then
                        FileString = Space(.zlfhFileNameLength)
                        Get #FNum, , FileString
                        'SlashPos = InStr(FileString, "/")
                        'If SlashPos <> 0 Then FileString = Left(FileString,
InStrRev(FileString, "/"))
                        Debug.Print "Got file: " & FileString
                        ReadZip.Add FileString, FileString
                    Else ' No filename?
                        Debug.Print "Got file: [No name]";
                        ReadZip.Add FileString, "No File Found"
                    End If

                    ' Print the compression percentage
'                    Debug.Print " -- " & Format(1 - (.zlfhCompressedSize /
_
'                        .zlfhUncompressedSize), "0.0%")

                    ' Work out how much extra data to skip over
                    SeekSize = .zlfhCompressedSize
                    If (.zlfhExtraFieldLength) Then _
                        SeekSize = SeekSize + .zlfhExtraFieldLength
                    If (.zlfhBitFlag And &H4) Then _
                        SeekSize = SeekSize + 12

                    ' Seek to next record
                    Seek #FNum, Seek(FNum) + SeekSize
                End With

            Else
                Exit Do
            End If
        Loop
    Close #FNum
End Function

Public Function FileExists(ByVal sPathName As String) As Boolean
    On Error Resume Next
    FileExists = (GetAttr(sPathName) And vbNormal) = vbNormal
    On Error GoTo 0
End Function

-HTH

Matt

Show quoteHide quote
"Matt Williamson" <ih8spam@spamsux.org> wrote in message
news:Ozbw2XdzFHA.2076@TK2MSFTNGP14.phx.gbl...
> Ah, that's a bit harder to do. Still fairly easy in the grand scheme of
> things though. I have a routine that I found in the archives awhile back
> that I modified to open a zip file and read the files within it into a
> collection. I'll dig it out and post it up for you when I find it. Then,
> it's just a matter of adding that in with the code I posted earlier.
>
> HTH
>
> Matt
>
> "Dave S" <h***@thestore.com> wrote in message
> news:bhx2f.38378$Xa.16826@fe12.lga...
>> Hi Matt,
>> I wasn't sure which file name you wanted so I listed both of them.
>> It was easier for me to use a small zip for a test than to move the .PK3
>> files.
>> I didn't think it would matter, thinking I can change .zip for .pk3 and
>> change the search string from .bmp to .bspPK* or what ever I need in the
>> future.
>>
>> File being searched for: (untitled is actual name)
>>    -  untitled.zip (contains 1 file - untitled.bmp)
>>
>> The string i'm searching for in zip:
>>    -  *bmp
>>
>> Generated file with found strings:
>>    -  Outputfile.txt
>>
>> Note: when I ran the previous test I copied the above zip several times.
>>        The file names were same, just preceded with "Copy of" .
>>        So I could see the changes when I stepped through the code.
>>
>
>
Author
10 Oct 2005 6:50 PM
Someone
Hi,

You could find a lot of folder search routines here. Look under "File &
Folder Search" category:

http://vbnet.mvps.org/index.html?code/fileapi/index.html

To unzip a file, use the freely available InfoZip with command lines
argument, or the DLL version in your VB6 program:

http://www.info-zip.org/

InfoZip is available as a command line EXE, and as a DLL that you could use
with Declare statement. This DLL is a standard DLL and does not require
registration(not ActiveX/COM DLL). If you use it, install it in your App's
folder to make sure that your App uses that specific DLL in case someone
installs incompatible version in the SYSTEM folder in the user's system.
InfoZip can also compress a bit stream(a byte array) on the fly to save
bandwidth if you want to transmit later by TCP/IP or a serial port.

Before reading a ton of documentation about InfoZip, see the sample here on
top of the page, UnzipFile() function is what you need. I used it
successfully:

http://home.modemss.brisnet.org.au/~mlevoi/dos.html

'
'   UnzipFile
'
'   INPUT
'       ZipFileName     Zip filename including path
'       ExtractDir      Extract to folder, can end with or without "\"
'
'   RETURNS
'
'       0       Success
'       <>0     Failure
'
Public Function UnzipFile(ByVal ZipFileName As String, ByVal ExtractDir As
String) As Long

Finally, make sure that you exclude the output folder from your searches,
Zip files can contain other zip files, unless you want to do that too.


Show quoteHide quote
"Dave S" <h***@thestore.com> wrote in message
news:zex1f.9536$Ge5.9496@fe10.lga...
>I had posted this in comp.lang.visual.basic and haven't recieved a reply
>    (to be fair it's only been one day), but then came across this group
> and there is much more activity here..
> My apologies for cross posting(?) .
>
> Hello all,
> Hope this is the correct group for this question.
> I couldn't find a vb beginners group.
> I am getting overwhelmed and need some help.
> I did this very easily in a batch file (only three lines), but DOS is too
> limited and the use of the batch is presenting other problems (file is
> compressed so I get garbage characters in the output file which I can't
> edit).
> I also wanted some other functionality added and decided to try VB6.
>
> Problem -  (Totally lost and frustrated)
>    How do I search all files with a given extension (ex. *.zip) for text
> inside
> those files and output those lines (strings) to a text file?
> I need to be able to use wildcards, so from what I read the use of the
> File
> System Object is not going to help me.
> The files are compressed (don't know if that matters).
> The text lines (strings) in the files I am looking for would be something
> like *.bspPK(trailing garbage characters)
>
> Any help will be much appreciated.
> Thank you
>
>
>
Author
10 Oct 2005 6:54 PM
Someone
This software might do what you want:

http://www.zipscan.co.uk/

More:
http://www.google.com/search?as_q=search+zip+extract&num=100


Show quoteHide quote
"Dave S" <h***@thestore.com> wrote in message
news:zex1f.9536$Ge5.9496@fe10.lga...
>I had posted this in comp.lang.visual.basic and haven't recieved a reply
>    (to be fair it's only been one day), but then came across this group
> and there is much more activity here..
> My apologies for cross posting(?) .
>
> Hello all,
> Hope this is the correct group for this question.
> I couldn't find a vb beginners group.
> I am getting overwhelmed and need some help.
> I did this very easily in a batch file (only three lines), but DOS is too
> limited and the use of the batch is presenting other problems (file is
> compressed so I get garbage characters in the output file which I can't
> edit).
> I also wanted some other functionality added and decided to try VB6.
>
> Problem -  (Totally lost and frustrated)
>    How do I search all files with a given extension (ex. *.zip) for text
> inside
> those files and output those lines (strings) to a text file?
> I need to be able to use wildcards, so from what I read the use of the
> File
> System Object is not going to help me.
> The files are compressed (don't know if that matters).
> The text lines (strings) in the files I am looking for would be something
> like *.bspPK(trailing garbage characters)
>
> Any help will be much appreciated.
> Thank you
>
>
>
Author
12 Oct 2005 12:24 AM
Dave S
Thanks for the info on the websites.
However, searching for files and folders and unzipping compressed files is
not the problem I am facing.
As I stated in prior post, I am looking for strings within a compressed
file.
I also do not have the option of using 3rd party software as someone else
had mentioned to me.
I do appreciate your taking the time to post the links.
The VBnet Developers Resource Center has a lot of valuable info and I am
sure I will spend a good amount on the site.
Author
12 Oct 2005 1:16 AM
Duane Bozarth
Dave S wrote:
>
> Thanks for the info on the websites.
> However, searching for files and folders and unzipping compressed files is
> not the problem I am facing.
> As I stated in prior post, I am looking for strings within a compressed
> file.

Unless the compression is a one-for-one algorithm over short sections,
the search would have to be on the uncompressed text.  Otherwise you'll
have to find the equivalent compressed version of the string you're
wanting to find and look for it.

So, in essence, searching for files and folders and unzipping compressed
files <is> the heart of the problem you're facing...
Author
12 Oct 2005 1:12 AM
Dave S
Matt,
That last bit of code worked for me also (winXP box).
I stepped through the code as you had told me prior and saw the action
taking place.
Then I added the .bas file to a form and added the Call to a Command Button.
It created the output file and added the .bmp entries to the output file.
Your AWESOME!!
It will take me a bit to see how to implement it into my project as far as
using the InputBox as a user path.
I figured how to do that in a function earlier, so I am hoping I can use
that for the path in your code instead of hard coding the path, as it needs
to be dynamic.
But I have been reading a lot and Larry has given me quite a bit of info in
working with the batch file as well.
Unfortunately, I thought the batch bit was working out, but I was coding on
a win2000 box and when I implemented the program on a winXP box I got -Run
Time Error "5"-Invalid Procedure Call or Argument on the Shell procedure and
can not figure out how to correct it. Seems like XP don't like it much.
Very frustrating.
Anyway,
I will be going out of State in a day or two (hopefully) so I'm not sure
exactly when I will get back to my project.
But I want to thank You and Larry very much for taking the time and having
the patience to deal with my questions.
I am very happy I came upon this group.
Seems like a nice group of helping and informed people here.
Hopefully I can return the favor some day to someone else in need of some
help.
I'll post on my success with the code when I get back.
Thanks Again !
Dave S
Author
12 Oct 2005 12:00 PM
Matt Williamson
Dave-

Just declare a variable for the inputbox like

dim sPath as string

sPath = InputBox("Type path to zip directory")


like this:

Sub Main()

Dim sFileName As String, ff As Long
Dim sOutputFile As String, sPath As String
Dim vFiles As Variant

sOutputFile = "C:\Outputfile.txt"
sPath = InputBox("Type path to zip files", "Input Path")
ff = FreeFile 'valid free file handle
Open sOutputFile For Append As #ff
sFileName = Dir$(sPath & "\*.zip", vbDirectory) ' all zip files in a
directory
Do While sFileName <> ""
    For Each vFiles In ReadZip(sPath & "\" & sFileName)
        If InStr(vFiles, ".bmp") <> 0 Then ' contains search string
          Print #ff, vFiles  ' write filename to output
        End If
    Next
sFileName = Dir 'next file
Loop
Close #ff

If you want a better way than the inputbox to supply the path, do a search
in the archive for BrowseForFolders.

-HTH

Matt

Show quoteHide quote
"Dave S" <h***@thestore.com> wrote in message
news:MpZ2f.2955$Hm3.1344@fe09.lga...
> Matt,
> That last bit of code worked for me also (winXP box).
> I stepped through the code as you had told me prior and saw the action
> taking place.
> Then I added the .bas file to a form and added the Call to a Command
> Button.
> It created the output file and added the .bmp entries to the output file.
> Your AWESOME!!
> It will take me a bit to see how to implement it into my project as far as
> using the InputBox as a user path.
> I figured how to do that in a function earlier, so I am hoping I can use
> that for the path in your code instead of hard coding the path, as it
> needs to be dynamic.
> But I have been reading a lot and Larry has given me quite a bit of info
> in working with the batch file as well.
> Unfortunately, I thought the batch bit was working out, but I was coding
> on a win2000 box and when I implemented the program on a winXP box I
> got -Run Time Error "5"-Invalid Procedure Call or Argument on the Shell
> procedure and can not figure out how to correct it. Seems like XP don't
> like it much.
> Very frustrating.
> Anyway,
> I will be going out of State in a day or two (hopefully) so I'm not sure
> exactly when I will get back to my project.
> But I want to thank You and Larry very much for taking the time and having
> the patience to deal with my questions.
> I am very happy I came upon this group.
> Seems like a nice group of helping and informed people here.
> Hopefully I can return the favor some day to someone else in need of some
> help.
> I'll post on my success with the code when I get back.
> Thanks Again !
> Dave S
>
Author
12 Oct 2005 4:59 PM
Dave S
Matt,
    I did exactly as you just posted last night on my own.
    Guess I am learning a little, nice feeling.

However, I ran across a possible problem in using your code.

As I posted earlier, I ran that test and it worked fine.
That was on 2 files.
I ran it on about 5 and got a "Over Flow error" on this line -
        ' Print the compression percentage -
  Debug.Print " -- " & Format(1 - (.zlfhCompressedSize /
..zlfhUncompressedSize), "0.0%")

I may have made an error in putting the code from here onto the .bas, due to
the word wrapping in here.
There was a few ' comment markers I didn't understand why they were in the
place they were and an _ also.
But when I ran the code, VB tagged it as unknown character or expected
(something),
so based on that I think I put it back together correctly until VB gave me
no more errors like that.

Do you think the overflow was due to trying the search on multiple files?
I tried playing with the "0.0%" value and kept getting the same error.
Regardless of the value. I did not try negative values.
Finally I commented it out, expecting other lines to now have errors, but
the code ran thru and my output.txt file contained the 5 search strings from
the 5 compressed files.
Matt, don't forget I am a total beginner. Most of your code I don't
understand.
    Also my math skills are very poor so understanding anything complex is
way out of my scope of understanding.
I  may not be leaving for another day or so due to the weather, so I will
keep working with this until I leave.

Dave
Author
12 Oct 2005 7:21 PM
Matt Williamson
Dave-

Those lines were commented out because they're not necessary. I left them in
and commented though, in case you wanted to experiment a little. The
Debug.print line is only for development use and does nothing during
runtime. It is used to print the value preceding it to the Immediate window
for debugging code. The _ is just a line continuation char in VB. Alot of
people that post code to the newsgroups use it in their code if the lines
are long so the copy/paste into vb won't need much editing and they make the
code easier to read too. The _ has to be the last char on the line prefixed
by a space char to work properly.

-HTH

Matt


Show quoteHide quote
"Dave S" <h***@thestore.com> wrote in message
news:Ohb3f.4080$Hm3.1913@fe09.lga...
> Matt,
>    I did exactly as you just posted last night on my own.
>    Guess I am learning a little, nice feeling.
>
> However, I ran across a possible problem in using your code.
>
> As I posted earlier, I ran that test and it worked fine.
> That was on 2 files.
> I ran it on about 5 and got a "Over Flow error" on this line -
>        ' Print the compression percentage -
>  Debug.Print " -- " & Format(1 - (.zlfhCompressedSize /
> .zlfhUncompressedSize), "0.0%")
>
> I may have made an error in putting the code from here onto the .bas, due
> to the word wrapping in here.
> There was a few ' comment markers I didn't understand why they were in the
> place they were and an _ also.
> But when I ran the code, VB tagged it as unknown character or expected
> (something),
> so based on that I think I put it back together correctly until VB gave me
> no more errors like that.
>
> Do you think the overflow was due to trying the search on multiple files?
> I tried playing with the "0.0%" value and kept getting the same error.
> Regardless of the value. I did not try negative values.
> Finally I commented it out, expecting other lines to now have errors, but
> the code ran thru and my output.txt file contained the 5 search strings
> from the 5 compressed files.
> Matt, don't forget I am a total beginner. Most of your code I don't
> understand.
>    Also my math skills are very poor so understanding anything complex is
> way out of my scope of understanding.
> I  may not be leaving for another day or so due to the weather, so I will
> keep working with this until I leave.
>
> Dave
>