Solved

Reterivieving all of the files from a directory

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now