# The &kfilereplace; Handbook

Emiliano
Gulmini

    emi_barbarossa@yahoo.it

2004
Emiliano Gulmini
&FDLNotice;
2004-08-09
1.0.0

&kfilereplace; is an utility to search and replace strings.

KDE
KFileReplace
replace
search
string

## Introduction

&kfilereplace; is an application used to search and replace a list of strings in a file tree. The strings may be literal or Qt-like regular expressions. There are also other options to tune your search.

## Using &kfilereplace;

&kfilereplace; in its standalone incarnation &kfilereplace; in its standalone incarnation

### The Toolbar

The &kfilereplace; toolbar should looks like this: &kfilereplace;'s toolbar &kfilereplace;'s toolbar

The toolbar shows you the buttons of the main functionalities.

#### Toolbar Icons

New session

  This button shows a session dialog in which you can set several basic options; if &kfilereplace; run as standalone application you should click this button as first step.

Search only

  This button starts a search loop.

Replace

  This button starts a search&replace loop. When a string has been found, &kfilereplace; replaces it with another string.

Simulated Replace

  This button starts a simulated search&replace loop. Nothing really happens when you click this button.

Stop

  This button stops an operation.

Add Strings

  This button opens the Add Strings dialog in which you can edit your string list.

Delete Strings

  This button deletes the selected (or the current if there is no selection) string from the list.

Edit Strings

  This button edits a selected string.

Delete List

  This button deletes all the strings in the list.

Invert Strings

  This button swaps the search string with the replace string, so you can revert a search/replace operation.

Load String List

  This button loads a string list saved in a xml file with a `kfr` extension.

Search in Subfolders

  This button allows you to search/replace recursively in the subfolders of your base directory.

Make Backup Files

  This button enables generation of backup files.

Case-sensitive Search

  This button enables case-sensitive searching.

Commands

  This button enables commands capability. Commands are special strings. See .

Regular expressions

  This button enables Qt-like regular expressions.

### The Results List

&kfilereplace;'s Results view
&kfilereplace;'s Results view

The Results view shows the name of the files that contain the strings you have to retrieve (and replace), their path, their size, the number of strings found and the user id of the files. This view also provides the exact position of each match. You can also open a file by clicking with the &RMB; on an list entry that contains line and column position.

### The String List

This is the Strings view: &kfilereplace;'s Strings view &kfilereplace;'s Strings view

The Strings view visualizes the list of strings you want search/replace. Please note that in search mode the Results view and the Strings view have a different layout.

### The New Session Dialog

The New Session dialog is used to setup the basic parameters needed by &kfilereplace; to work. It consists of two tabs, General and Advanced.

#### The General Tab

&kfilereplace; General tab
&kfilereplace; General tab

When you want to begin a new session the first step is to click on the New Session button. Then you must enter the base path and a sequence of shell-like wildcards to use as filter.

Then you could set some useful options, like searching in all the subfolders, doing a case-sensitive search, enabling commands and/or regular expressions Please note that regular expressions and commands could slow down the speed performances., doing a backup copy of each file before replacing.

If you want to start searching, you can put a string in the search box and press Search Now, otherwise leave the search box empty and press Search Later.

#### The Advanced Tab

&kfilereplace; Advanced tab
&kfilereplace; Advanced tab

The Advanced tab allows you to set up some useful options to restrict the search to a subset of your target file tree. If you want to run &kfilereplace; only over files that have a size in the range of 10KB - 100KB, then you could use the size options. There is also a date option that restricts the search in a temporal range, and a last option that allows you to only search for files owned (or not owned) by a particular user (this may be more useful to the system administrators).

### The Options Dialog

This dialog contains options that are in the toolbar and extra options that may come in handy in some situations. You can invoke it selecting Settings Configure KFileReplace... in the main menu.

#### General options

These options have been presented in the Toolbar section. The General tab of the Options window The General tab of the Options window

#### Advanced options

The Advanced tab of the Options window The Advanced tab of the Options window Do not show files if no strings are found or replaced When searching, stop on first string found Follow symbolic links Ignore hidden files and directories shows only the files that match some of your strings. This will speed up the search. &kfilereplace; will stop when it finds a matching string, and will continue to search for other strings or, if you search for only one string, it will continue with the next file. if a file is a link to another one, then search in the real file. if hidden files or folders are encountered, ignore them.

### The Add Strings Dialog

&kfilereplace;'s Add Strings dialog
&kfilereplace;'s Add Strings dialog

This dialog is used to insert and edit a list of strings. You just have to insert either a search-only or a search-and-replace list, and then with the two mini-editors you will introduce your text. The arrow buttons allow you to add pairs of strings or delete them. When you finish, click OK.

## &kfilereplace; features

This chapter provides informations about some useful capabilities of &kfilereplace;.

### How to save your string list

When you want to reuse a list of strings you can save it in a `xml` file. To do this select from the menubar Search/Replace Strings Save Strings List to File. When you save a list, a simple `xml` file with extension `kfr` is created. To load a `kfr` file select from menubar Search/Replace Strings Load Strings List from File. The actual file looks like this:

    <?xml version="1.0" ?>
    <kfr>
    	<mode search="false"/>
    	<replacement>
    		<oldstring><![CDATA[SEARCH_STRING_1]] ></oldstring>
    		<newstring><![CDATA[REPLACE_STRING_1]]></newstring>
    	</replacement>
    	<replacement>
    		<oldstring><![CDATA[SEARCH_STRING_2]]></oldstring>
    		<newstring><![CDATA[REPLACE_STRING_2]]></newstring>
    	</replacement>

    	<replacement>
    		<oldstring><![CDATA[SEARCH_STRING_N]]></oldstring>
    		<newstring><![CDATA[REPLACE_STRING_N]]></newstring>
    	</replacement>

    </kfr>

If you are using a previous format, you can update by hand your file by simply modifying it according to the above scheme. Alternatively, you can load the file written in the old format and save it again with &kfilereplace; in the way explained before.

### How to Create a Simple Report

You can create a report by choosing Search/Replace Results Create Report File from the main menu. A report is a folder containing an `xml` and a `css` file. Reports may be useful to maintain a simple log of your operations. &kfilereplace;'s Report feature &kfilereplace;'s Report feature

### How to use Regular Expressions

If you want search for every string that starts with x, ht or u and ends with ml, you can write a regular expression like this: `(x|ht|u)ml`. Insert this expression in the search editor, click OK, and enable regular expressions by toggling the Regular Expression button. Please note that using regular expressions lets you to make very complicated searches, but the cost could be a performance degradation. Regular expression can be very tricky, and it is often the case that if you want to solve a problem with a regular expression, you have two problems.

### How to Protect Original Files

If you do not want to lose your original files, you can make a copy of them before replacing the strings. After inserting your strings, and before starting the replacement process, you have just to toggle the Backup button. If you want to customize the extension of the backup files open the Options dialog.

### How to Open a File

If you want to open a file that matches some of your strings, you have to select a line in the result view and click on it with the &RMB;. A context menu will appear from which you can open the file. If you use &kfilereplace; embedded in &quantaplus;, you can open the file directly in it at the specified line and column.

### Commands

Suppose you want replace the phrase Alice's adventures in Wonderland with the entire file that contains Carroll's novel. Probably you don't want to do this by hand, what you need is a command that will do it for you. Click the Add button, select Search and Replace Mode and insert the following strings: `Alice's adventure in Wonderland` in the search mini-editor and the string `[$loadfile:/the-path-to-my-folder/my-folder/my-file$]` in the replacement mini-editor. Click OK. When you come back to the &kfilereplace; main window, toggle the Command action button that enables the commands, and start the replacement process. There are also other commands, see for a list of all of them.

## Credits and License

&kfilereplace;. Program copyright 1999 by François Dupoux dupoux@dupoux.com, 2003 Andras Mantia amantia@kde.org, 2004 Emiliano Gulmini emi_barbarossa@yahoo.it

### The &kfilereplace; authors and maintainers:

François Dupoux dupoux@dupoux.com

  Original author

Andras Mantia amantia@kde.org

  Shell autor, KPart creator, co-maintainer

Emiliano Gulmini emi_barbarossa@yahoo.it

  Current maintainer, code cleaner & rewriter

Documentation Copyright © 2004 Emiliano Gulmini emi_barbarossa@yahoo.it

&underFDL; &underGPL;

## Installation

### How to install &kfilereplace;

&kfilereplace; is currently part of &kdewebdev; package, so, in order to install it, you have to get a copy of &kdewebdev;. Note that if you are using a &kde; installation provided by your OS vendor, probably you already have &kdewebdev; installed; in this case, you can use &kfilereplace; either by opening &quantaplus; Web editor, or by calling it directly (unless you have an old &kde; version). Else you can download the &kdewebdev; package from the Internet: please refer to &kdewebdev; home site for more information.

### Requirements

In order to use the command [$mathexp:some_math_expression$] you should install the &bc; mathematical utility (version 1.06 or newer) written by Philip A. Nelson (philnelson@acm.org).

## &kfilereplace; commands

[$datetime:iso$] [$datetime:local$] [$user:uid$] [$user:gid$] [$user:loginname$] [$user:fullname$] [$user:homedir$] [$user:shell$] [$loadfile:/my-path/my-directory/my-file$] [$empty:$] [$random:AN_INTEGER_NUMBER$] [$random:$] [$mathexp:bc-expression$] this command return the current date and time in Qt ISO format. like above but in local format. return the UID of the current user. return the GID of the current user. return the login name of the current user. return the full name of the current user. return the home directory of the current user. return the shell of the current user. return the content of the my-file file. return the empty string. return a random number string using AN_INTEGER_NUMBER as the initial seed. like above, but without initial seed. return the result of a &bc; v1.06 mathematical expression.

&documentation.index;