Solved

Reterivieving all of the files from a directory

Posted on 2002-05-28
5
200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

789 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