FILEMONKEY FAQ
Copyright MonkeyJob Systems 2005
All rights reserved

Home FAQ Forums Contact
Download Tutorials FAQ Awards Report Bugs
 Search For Data
   

Replacing text within files with file name or other text



Note that since the release of FileMonkey version 9.8, this operation is now much easier using the "Replace" feature.

The following tutorial will show you how to use FileMonkey to search for text within each target file and replace that text with either the name of the respective file or some other text.

This tutorial will use the "Command Line" feature of FileMonkey.

1.

In the main window, target the files that you wish to work on (Click HERE for a targeting tutorial).

2.

Select the "Quick-Find, Command Line" menu item from the main window.


Fig 1
make batch jobs

3.

This will load the command line window (See Fig 1 above).

From the menu bar at the top of this window, select the "File / Load Code" menu item.

4.

This will open the "Load File" window (see Fig 2 below)

Fig 2
find script

5.

Select the "Search Replace.FM" script and click on the "Load" button to load the script.

6.

Find the following line:

Set dosloc="C:\Program Files\FileMonk\DOSSR.exe"

Fig 3
edit dos search replace

7.

This line will read "C:\Program Files\FileMonk\DOSSR.exe". This is the location of the command line search and replace module that we have written for this tutorial (DOSSR.exe).

By default, this will be in the folder that you have installed FileMonkey in. If you have installed FileMonkey in a different folder then you will need to change this line yourself to reflect the location of DOSSR.exe.

8.

To work on all target files, regardless of file attributes, select the "Work On All Files" option.

9.

Next, we need to set the search and replace phrases. To do this, you need to manually edit the file section of the script.

Select the "File" tab near at the top center of the command line window.

10.

The command line window should now look like Fig 4 below.

Fig 4
search replace phrase

11.

As you can see from Fig 4 (above) there are 2 sections that you need to manually edit. These are: The search phrase and the replace phrase.

Enter the search phrase and the replace phrase that you want to use in their respective places, encompassing both phrases in double quotes (""). Here are a few examples:


Example 1:
If I want to search for "hello" and replace it with "goodbye", I would change this line to:

%dosloc% "<myDosFold><myDosFile>" "hello" "goodbye"


Example 2:
If I want to search for "$" and replace it with the name of the file that contains the "$", I would change this line to:

%dosloc% "<myDosFold><myDosFile>" "$" "<myFile>.<myExt>"


Example 3:
If I want to search for "<title>$" and replace it with "<title>" + the name of the file that contains the search phrase, I would change this line to:

%dosloc% "<myDosFold><myDosFile>" "<title>$" "<title><myFile>.<myExt>"


Example 4:
If I want to search for the text "current path" and replace it with the path of the file that is currently being worked on, I would change this line to:

%dosloc% "<myDosFold><myDosFile>" "current path" "<myPath>"

12.

To start the operation, select the "File / Compile And Run" menu item.



Related Topics:
FileMonkey Tutorials
Frequently Asked Questions
Search and replace from the command line
Search and replace on file names example
Search and replace on file contents example
Search for information (without replacing)

  | About Us | Privacy Policy | Terms Of Use | Affiliates | Forums | Copyright ©2003 MonkeyJob Systems All Rights Reserved |