TDEFileReplace"> tdeutils"> bc"> ]> The &tdefilereplace; Handbook Emiliano Gulmini
emi_barbarossa@yahoo.it
2004 Emiliano Gulmini &FDLNotice; 2004-08-09 1.0.0 &tdefilereplace; is an utility to search and replace strings. TDE TDEFileReplace replace search string
Introduction &tdefilereplace; is an application used to search and replace a list of strings in a file tree. The strings may be literal or TQt-like regular expressions. There are also other options to tune your search. Using &tdefilereplace; &tdefilereplace; in its standalone incarnation &tdefilereplace; in its standalone incarnation The Toolbar The &tdefilereplace; toolbar should looks like this: &tdefilereplace;'s toolbar &tdefilereplace;'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 &tdefilereplace; run as standalone application you should click this button as first step. Search only This button starts a search loop. Simulated Replace 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, &tdefilereplace; replaces it with another string. 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. 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 &tdefilereplace;'s Results view &tdefilereplace;'s Results view The Results view shows the name of the files that contain the strings that match the search criterias, their path, their size, the number of strings found, the user and group of the files owner. This view also provides the exact position of each match. The columns can be sorted either ascending or descending by clicking on the column headers. You can open a file by clicking with the &RMB; on a list entry, by single/double clicking (depending on your mouse settings) on an entry or alternatively by selecting an item and pressing Enter. You can inspect the file properties using Properties from the &RMB; menu. You can also delete a file from the file system using Delete or simply remove the item from the results list using the Remove Entry command. The String List This is the Strings view: &tdefilereplace;'s Strings view &tdefilereplace;'s Strings view The Strings view visualizes the list of strings you want to search for and eventually replace with. Please note that the layout of both the Results view and the Strings view is different if you are only searching or if you are searching and replacing. The <guilabel>Customize Search/Replace Session</guilabel> Dialog The Customize Search/Replace Session dialog is used to setup the basic parameters needed by &tdefilereplace; to work. It consists of two tabs, General and Advanced. The <guilabel>General</guilabel> Tab &tdefilereplace; General tab &tdefilereplace; 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 including limiting the max depth of searching, doing a case-sensitive search, enabling commands and/or regular expressionsPlease 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 <guilabel>Advanced</guilabel> Tab &tdefilereplace; Advanced tab &tdefilereplace; 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. You can set restrictions on the size, access date and ownership of the files to be searched for. The <guilabel>Options</guilabel> 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 SettingsConfigure TDEFileReplace... in the main menu. General options These options have been presented in the Toolbar section. In addition to those, you can specify the default file encoding to use and the suffix for backing up files. 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 Confirm before replace each string 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 choose whether to confirm the replacement of each string or not. shows only the files that match some of your strings. This will speed up the search. &tdefilereplace; 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 <guilabel>Add Strings</guilabel> Dialog &tdefilereplace;'s Add Strings dialog &tdefilereplace;'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. &tdefilereplace; features This chapter provides informations about some useful capabilities of &tdefilereplace;. 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/ReplaceStringsSave 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/ReplaceStringsLoad Strings List from File.... The actual file looks like this: <?xml version="1.0" ?> <kfr> <mode search="false"/> <replacement> <oldstring><SEARCH_STRING_1></oldstring> <newstring><REPLACE_STRING_1></newstring> </replacement> <replacement> <oldstring><SEARCH_STRING_2></oldstring> <newstring><REPLACE_STRING_2></newstring> </replacement> ... ... <replacement> <oldstring><SEARCH_STRING_N></oldstring> <newstring><REPLACE_STRING_N></newstring> </replacement> </kfr> How to Create a Simple Report You can create a report by choosing Search/ReplaceResultsCreate 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. &tdefilereplace;'s Report feature &tdefilereplace;'s Report feature You can also save and load the results list contents to/from file using the Search/ReplaceResultsSave Results List to file... and Search/ReplaceResultsLoad Results List from file.... This is very useful if you are searching over a lot of files and for many strings, so you can save and resume your checks across multiple days. 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 You can open a file by clicking with the &RMB; on a list entry, by single/double clicking (depending on your mouse settings) on an entry or alternatively by selecting an item and pressing Enter. If you use &tdefilereplace; 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 &tdefilereplace; 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 &tdefilereplace;. Program copyright 1999 by François Dupoux dupoux@dupoux.com, 2003 Andras Mantia amantia@kde.org, 2004 Emiliano Gulmini emi_barbarossa@yahoo.it The &tdefilereplace; 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; 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). &tdefilereplace; 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 TQt 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;