?
Solved

multi-file  search and replace

Posted on 2003-03-25
9
Medium Priority
?
215 Views
Last Modified: 2010-04-04
Hello

Can somebody help me with some sourse code or a link where I can find a example with source

ho to make a file Grep for multi-file search and replace in multi directories

Thanks

Regards

Zip58
0
Comment
Question by:Zip58
[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
  • 4
9 Comments
 
LVL 3

Expert Comment

by:lmikle
ID: 8205866
Simple find files and process them. Use FindFirst/FindNext/FindClose functions to find files.

// this procedure process single file
procedure ProcessFile(FileName, SearchStr, ReplaceStr : String);
begin
...
end;

// this procedure recieve a list of folders name
// that must be processed and start processing of them.
// Folders name is the full folder name
// with the ending slash: "C:\MyDocs\" for example
procedure ProcessFolders(FldrList : TStringList; SearchStr, ReplaceStr : String);
var
  I : Integer;
begin
  For I := 0 To FldrList.Count-1 Do
    ProcessFiles(FldrList, SearchStr, ReplaceStr);
end;

procedure ProcessFiles(FolderName, SearchStr, ReplaceStr : String);
var
  iFound : Integer;
  SR : TSearchRec;
begin
  // Find all files and folders
  iFound = FindFirst(FolderName+'*.*',faAnyFile,SR);
  While iFound = 0 Do
    Begin
      if (SR.Attr And faDirectory) <> 0
        Then
          Begin
            // folder was found - proces it in depth.
            // if you don't need hierarhial search - disable this brunch
            If (SR.Name <> '.') and (SR.Name <> '..')
              Then ProcessFolder(FolderName+SR.Name+'\',SearchStr,ReplaceStr);
          End
        Else
          Begin
            // file was found
            ProcessFile(FolderName+SR.Name,SearchStr,ReplaceStr);
          End;
      iFound := FindNext(SR);
    End;
  FindClose(SR);
end;

0
 
LVL 2

Author Comment

by:Zip58
ID: 8205921
Hi lmikle

Thanks for your replay but can you not make a little demo?

Regards

Zip58
0
 
LVL 3

Expert Comment

by:lmikle
ID: 8206016
Sorry, Demo of what?

Demo search and replace in single file?
0
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!

 
LVL 2

Author Comment

by:Zip58
ID: 8206091
Hi lmikle

What I will and if you can a little example programma from

search and replace in multi files and multi directories

Regards

Zip58
0
 
LVL 2

Author Comment

by:Zip58
ID: 8206580
Hi lmikle

What I will and if you can make a  little example programma from

search and replace in multi files and multi directories

Regards

Zip58
0
 
LVL 3

Accepted Solution

by:
lmikle earned 1000 total points
ID: 8209506
Hi Zip58.

The code above implement a basic alorithm to perform search and replace in a list of folders with subfolders.

In a visual part of program you simple must fill a source folders list and search and replace string. After than on any buttton click you mast call ProcessFolders procedure and pass into it a folders list and search and replace strings. Please post here your email address. I'll send you a little example (also please post a your Delphi version - curently i have installed versions 5 and 7 and can make this example on any of this version)
0
 
LVL 2

Author Comment

by:Zip58
ID: 8209563
Hi lmikle

Thanks for your replay my email adress is zip_58@hotmail.com

and my version is Delphi 5

Thanks in advance

Regards

Zip58

0
 
LVL 3

Expert Comment

by:lmikle
ID: 8209876
Dear Zip58.

I was sent a example to your email.
Remember - this is only example and the ProcessFile procedure is very simple and can do not work with binary or large files. I was test one on simple text files not larger than 1 Kb.

0
 
LVL 2

Author Comment

by:Zip58
ID: 8210351
Hi lmikle

Thanks for the example

if I need more info I will leave a message four you here in the forum

Thanks again

Regards

Zip58
0

Featured Post

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 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