Solved

Reterivieving all of the files from a directory

Posted on 2002-05-28
5
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 52

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

729 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