Solved

Reterivieving all of the files from a directory

Posted on 2002-05-28
5
195 Views
Last Modified: 2010-05-02
Hey Everyone...

Here what I am trying to do:

I have a directory with an ever changing number of txt files that I need to manipulate.  I need a way to collect all of the files of a certain extension(.msg) and read each file separately looking for a certain keyword(s).  Is there a way to read these files into an array and maniuplate them that way? or is their an easier way that I am missing.  Please let me know if you can help
0
Comment
Question by:dsplice
5 Comments
 
LVL 4

Accepted Solution

by:
gencross earned 100 total points
ID: 7040202
Something like this may do what you need.

    Dim sFile As String
    Dim sText As String
   
    Dim iFreeFile As Integer
   
    sFile = Dir("c:\*.txt")
   
    iFreeFile = FreeFile
   
    Do While sFile <> ""
       
        Open "c:\" & sFile For Input As iFreeFile
       
        sText = Input(LOF(iFreeFile), iFreeFile)
           
        If InStr(sText, "Look for") Then
            MsgBox "Text found"
        End If
       
        Close iFreeFile
       
        sFile = Dir
       
    Loop
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7040217
easy example:


Public function checkforkeyword(byval sPath as string, byval sKeyword as string)
Dim sFile as string, strBuf
sFile = Dir$("c:\*.msg")
Do While sFile<>""
   Open sFile For Binary As #lFile
   strBuff = Space$(LOF(lFile))
   Get #lFile, , strBuff
   Close #lFile
   If(InStr(1, strBuff, sKeyword)>0) Then msgbox sFile
   sFile = Dir$
Loop
end function

If it is for the web then I can really recommend index server for that which is from microsoft and allows exactly that. It may even have support for plain applications, though I am not sure of that.

CJ

0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 7040916
and use this to Reterivieving all of the files from a directory:

http://www.mvps.org/vbnet/code/fileapi/recursivefiles_minimal.htm
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7851208
Hi dsplice,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept gencross's comment(s) as an answer.

dsplice, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7912829
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question