# Scripting

Scripting is form of programming that allows you to extend Replace Genius and give it new functions! It is not particular hard, but it requires some basic knowledge of computer programming.

Scripts are simple textfiles with the file extension frs (Replace Genius Script). All scripts must be put in the Script folder inside the settings folder. To begin making your own script, I recommend that you have a look at the example distributed with Replace Genius, called Example - Base for New Script.frs.

If you create a useful script, send it to me and I might include it in the next version of Replace Genius!

Replace Genius use the Windows Script Host, which means that it can use any scripting language you have installed on your system. The default is VBScript. To use another language you must enter its name on the first line inside the script (see the example scripts).

Functions

When executing, Replace Genius will call the following functions inside your script.

- `Init()`

  (Optional) The Init function runs first of all, before anything else. If you return anything from this function it will be printed to the log window.

- `Rename()`

  Replace Genius will call this function for each file to rename. Return the desired new filename! Return an empty string to skip renaming the file.

- `Done()`

  (Optional) When all files have been renamed this function is called. If you return anything from this function it will be printed to the log window.

Exposed variables & functions

Replace Genius exposes parameters and functions though the read-only object `FlashRenamer`. The following are available at the moment:

- `FlashRenamer.Filename`

  This is the string that Replace Genius wants you to process. Note that it depends on the "Process Name" and "Process Extension" settings in Replace Genius.

- `FlashRenamer.FullFilename`

  This always contains the full filename, including extension, in contrast to the above. Use it for reference.

- `FlashRenamer.Path`

  This is simply the path where the file is located.

- `FlashRenamer.Args`

  The arguments you can enter when you run a script in Replace Genius are delivered through this variable.

- `FlashRenamer.FormatTags(myTag)`

  This is a function you can call to "render" a format string, just like format strings in Replace Genius. For example, FlashRenamer.FormatTags("<size>") will return the size of the file!

- `FlashRenamer.Preview`

  This is a boolean value (true or false) that tells you if your script is being run to generate the preview or if it is the "real deal".

- `FlashRenamer.DiskName`

  When running presets, multiple functions process the filename before writing it to disk. Since the filename may have been changed previous to entering your script, you should use .DiskName if you want to access the file on disk.

- `FlashRenamer.NumItems`

  This always contains to total amount of files that are destined to be renamed

- `FlashRenamer.ItemOrder`

  This contains a zero padded id repressenting the order in which the current item is located, relative to the rest of the items being renamed.

- `FlashRenamer.BrowserPath`

  This contains the path that is currently loaded in the file browser in Replace Genius. If using free select mode, this is empty.

- `FlashRenamer.GetAllFilenames`

  Returns a string containing all filenames included in the current rename set. Each filename is separated by an asterix (*).

Notes

- The second line of a scripting file may contain a short description of the script that will be displayed in Replace Genius.

- You can't assume that you get the files in correct order when renaming. A way around this is to use the ItemOrder property (See the included script Create mp3 playlist for an example). Another way is to use the <counter> tag in a smart way.