Reading files and inserting file names

You can insert the filename, another file contents, or file metadata into a replacement.

File name and path

The full file name is separated into three parts:

For example, you search in the C:\Documents directory and Aba found a match in C:\Documents\html\contacts.html. In this case:

Aba.searchPath() == 'C:\Documents\'
Aba.filePath() == 'html\'
Aba.fileName() == 'contacts.html'

Another example: Aba found a match in C:\Documents\index.html:

Aba.searchPath() == 'C:\Documents\'
Aba.filePath() == ''
Aba.fileName() == 'index.html'

You can combine some of these three parts to get the full file name or to address a file in the searched directory. Please concatenate the strings (see the examples below).

The read function


This function reads the whole file and returns its contents. It's useful for inserting one file into another. The inserted file must be 2 megabytes or smaller, otherwise Aba will display an error message. This is to prevent inserting multi-gigabyte files by mistake, which would hang Aba.

The file name can include an absolute path or it can be relative to the directory where the match is found. So if you need to address a file in the same directory as the file with the match, please use a relative path. If you need to insert the same file into files located in different directories, please use an absolute path with Aba.searchPath().

For example, you search in the C:\Documents directory and Aba found a match in C:\Documents\html\about.html.

Search forReplace toExplanation
</body> \{File('footer​.html').read()}</body> Insert C:\​Documents\​html\​footer.html
</body> \{File(Aba.searchPath() 'footer​.html').read()}</body> Insert C:\​Documents\​footer.html

Even when using an absolute path, the inserted file must be located in the Aba.searchPath() directory. This is for security reasons; otherwise, a malicious person could use Aba to read passwords or configuration files. So the script is not allowed to read outside of the directory that you specified for search. If you need to read from the parent directory, please include it into your search.

The meta function


This function returns binary file properties such as image height/width, mp3 ID3 tags, etc. It's similar to the getimagesize function in PHP, but more powerful. The rules for absolute/relative path are the same as for the read function.

You can use any Windows Property name by putting an equal sign before it. Aba also supports an ImgTag property that returns a width="..." height="..." string ready to insert into the <img> tag.

Some of the supported image properties (tested with PNG, JPEG, and WebP files):

ID3 tags from mp3/ogg files:

Search forReplace toExplanation
<img src="([^"]+)"> <img src="\1" \{File(\1).meta('ImgTag')}> Add width and height attributes to <img> tags
<a href="([^"]+\.mp3)"> <a href="\1" title="\{File(\1).meta('=System.​Media.​Duration')}"> Add audio duration as a title attribute to mp3 download links

If the property name is unknown, Aba displays the Element not found error message. However, if the property does not apply to this file type (e.g., =System.Image.HorizontalSize for an mp3 file), the function returns an empty string.

This is a page from Aba Search and Replace help file.