# The &kfilereplace; Handbook

Emiliano Gulmini

    emi_barbarossa@yahoo.it

2004 Emiliano Gulmini
&FDLNotice;
2011-08-16
0.1 (&kde; 4.7)

&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

Customize Search/Replace 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

  This button starts a search loop.

Simulate

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

Replace

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

Stop

  This button stops an operation.

Add String

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

Delete String

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

Edit Selected String

  This button edits a selected string.

Empty Strings List

  This button deletes all the strings in the list.

Invert Current String

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

Load Strings List From File

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

Include Sub-Folders

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

Create Backup Files

  This button enables generation of backup files.

Case Sensitive

  This button enables case-sensitive searching.

Enable Commands in Replace String

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

Enable 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 Search & Replace in Files Dialog

The Search & Replace in Files 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 Customize Search/Replace 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 Insert Searching/Replacing Strings Dialog

&kfilereplace;'s Insert Searching/Replacing Strings dialog
&kfilereplace;'s Insert Searching/Replacing 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 information 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.

### 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 author, 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 and Compilation

&install.intro.documentation; &install.compile.documentation;

### 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 folder 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;