2003 TextMaestro Technologies



  Example 1

  Example 2

  Example 3

  Example 4

  Example 5

  Example 6

  Example 7

  Example 8

  Example 9

  Example 10

  Example 11

  Example 12

  Example 13

  Example 14

  Example 15

  Example 16

  Example 17

  Example 18

  Example 19

  Example 20

  Example 21



Example 12: Rename Files

Renaming files under a batch operation is a canonical problem for any file-systems. In general, using a script to rename files is the solution. TextMaestro is a flexible tool to write such script. At the same time, you have the option to use GUI method to rename files. While script file method is suitable for any platforms, GUI method is for Windows only. Below we give examples to both. Before we begin, here is the game plan. We will discuss the following four items:

(0) Preparation before renaming files. (Needed for any method below.)

(a) Using TextMaestro GUI to rename files.

(b) Using TextMaestro GUI to rename files for advanced cases.

(c) Using a script file from a line window to rename files.

Similar to renaming files, you can duplicate multiple files. We leave this on users.


(0) Preparation before renaming files:         Top

Suppose you have a bunch of *.html files in xml-docs folder, and you would like to rename them as *.htm files.Note that the sub-folders here have sub-sub-folders and so on, and there are many .html files in those folders, possibly same filenames but in different folders. Our goal is to rename each .html file found on the path of recursion.







Drag and drop the xml-docs folder onto the lower list-box.

Since you are dragging a folder, TextMaestro will display Directory Usage dialog. (See Working with directories for details on Directory Usage). Use the setup as shown on the right below:

This dialog appears when a directory is drag-and-dropped onto the file-list.

Un-check Derive Remote directories based on local paths. Use .html in Keep.

Note Remote directory for all files (right picture above) cannot be left empty. Add anything in this filed. Hit OK. Below is the view after all the .html files are added.

Now we are ready to go. Renaming these files could be done in three ways as stated earlier:

(a) Using TextMaestro GUI.

(b) Using TextMaestro GUI with advanced features.

(c) Using a script file from a command window.

Method (a) is the simplest. We expect, this would be the default method of everyday file renaming tasks. However, when you need more power you can resort to method (b). Method (c), as powerful as method (b), is aimed for console driven environment, since it uses script file and has no dependency on TextMaestro GUI.



(a)  Using TextMaestro GUI to rename files:         Top

Suppose you have the files listed on TextMaestro as shown above. Now, from pull-down menu select: Files | Work on files | Multiple... | Rename/Duplicate multiple files (Ctrl+Shift+R). Alternatively, right click on the selection and select: Multiple... | Rename/Duplicate multiple files (Ctrl+Shift+R).


Then the following dialog will appear. The navigation and controls on this dialog are quite intuitive and it is likely that you will go on to make some experiments here. Before you do, we would like you to notice that 3. Using user specified extension is what you want here to rename all .html files to .htm extensions. Go ahead and select scheme 3. Enter .htm in place of extension.



Now if you hit on the large picture button with yellow arrow on it, the output file names will be prepared and displayed on the right list. Each name will now show .htm, instead of .html. (Actual files are not renamed yet.)






If you are satisfied with these names, click on Rename files to above new names button. And this will rename all the files on the main list using these names above.


If you want to modify one or some items of this list, you can do so by double-clicking on the item and modify the specifications in a dialog that comes up.


After the renaming is over, expect to see this view which denotes that all the files now have .htm extensions.




(b)  Using TextMaestro GUI to rename files for advanced cases.         Top

Note the last scheme on Rename/Duplicate Selected Files dialog, in particular,
5. Using names from Output window
. Although using the first four schemes one can almost always get around in renaming files, there comes time when you need more flexibility in deriving the output names. In that case you can use text conversion utility to derive the names, place them on Output window and later import them using scheme 5. Using names from Output window.


Here is an example. Suppose new names should appear like this:

Current names

New names













... ... ...













... ... ...

I.e., first letter of each name will be in upper case and the extension be .htm.

Hit Ctrl+R to open Report dialog. Accept the following specifications and hit on the Report button.




This will dump the report on the Input window. Using the text on Input window we will generate the desired list of destination filenames onto Output window. This time we will use a different definition in the Work Pad as shown below.

Use the following definition and hit the convert button.







This will generate new names in Output window. The Input and Output window are shown below.

In a nutshell, each line of the Output window is nothing beside the desired filename for each corresponding item in the list, where first letter is in upper case (due to the case qualifier 'p' after *1) and .html is replaced by .htm.


Each line is destination filename generated in Output window. An entry in Output window may contain file-path in addition to the filename. In that case the new file will be at the location dictated by the explicit file-path.


Now hit Ctrl+Shift+R, and Rename/Duplicate Selected Files dialog will appear. If you select scheme 5. Using names from Output window here, and click on View results button, you will see the following:


In summary, TextMaestro grabs the text found in Output window, and assigns its n-th line to the n-th file item.

Caution: It is your responsibility to make sure that the assigned line denotes a valid path and filename.

TextMaestro will create the destination directory if it does not exist, but will not perform any sanity check on the validation of a name.


Hit Rename files to above new names button. The process may take a few moments based on the number of files. After the renaming is over, expect to see this view, which denotes that first letter of each name is in upper case and the extension is .htm.


Everything you can do to rename files in method (a) and (b) above, you can do the same to duplicate files. Give it a try, and you will figure it out shortly.




(c)  Using a script file from a command window to rename files.         Top

Suppose you have the files listed on TextMaestro as discussed in (0) Preparation before renaming files step. (This picture was shown earlier).

We want to rename these files using a script. This method can take place on any console driven environment such as UNIX, VMS, Windows, etc. However you have to follow the command and scripting language of the environment. In contrast, GUI method works only on Windows.

Also note that writing script files is never a unique method. You can accomplish the same task using various types of scripts. What we presented below is just an example for Windows. By no means it is the best solution. Let us write a script file. We will use Report feature and one of the text conversion methods to accomplish it.


Select all items (Ctrl+A) in the list. Then hit Ctrl+R to open Report dialog. (This can also be accessed through Session toolbar). Set Fields and Gutter as shown below. Note we opted for Local directory and File name. Hit the Report button here.

This will list all the selected files preceded by their local paths in the Input window. See below (partial view):

Now using this text on Input window, we will create the script file on the Output window using text conversion. Here is the settings of the conversion.



cd <$1>

rename <$2> <$2?.html=.htm>



Here is the macro definition and the Output window:


The rules behind the Macro definition are explained here in details. It is worth while to review these rules. In a nutshell, each line in Input window has two tokens - first token is an absolute path, the second is a file name. <*1> stands for absolute path and <*2> for filename. So the command is:

cd <absolute path>

rename <file-name> <file-name where .html is replaced by .htm>

Hit the Convert button to obtain above output. Copy the text from Output window to clip-board. Open a cmd window. (You can open a cmd window using Launch telnet button while holding down control key and selecting cmd, the last item in the combo-box).

Just paste the copied text on the cmd window as shown below. That will rename each .html file in the list.

Please keep in mind that the Output window text may contain a large number of lines, based on the number of files in the list. It is a good practice to try two or three pairs of commands and see if the script is right or not. Then you can dump the whole text on the console.


Now that the files are renamed, the main list box will display them as missing as shown below.