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:
Aba.searchPath()
is the directory that you selected in the Aba main window. The returned value always ends with a backslash.Aba.filePath()
is the relative path of the file where Aba found the match (relative to thesearchPath
). ThefilePath
can be an empty string if the file resides in the selected directory itself, not in its subdirectories. If thefilePath
is not empty, it always ends with a backslash.Aba.fileName()
is the file name without any path.
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
File(fileName).read()
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 for | Replace to | Explanation |
</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
File(fileName).meta(propertyName)
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):
- =System.Image.HorizontalSize is the image width;
- =System.Image.VerticalSize is the image height;
ImgTag
are width and height attributes for an <img> tag.
ID3 tags from mp3/ogg files:
- =System.Music.Artist is the artist;
- =System.Title is the song title;
- =System.Music.AlbumTitle is the album title;
- =System.Media.Year is the year when the record was published;
- =System.Music.TrackNumber is the track number on the album;
- =System.Music.Genre is the genre as a text string;
- the ID3 comment is currently unavailable;
- =System.Media.Duration is the audio duration in the hours:minutes:seconds format.
Search for | Replace to | Explanation |
<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.
- Welcome to Aba
- Getting started
- How-to guides
- Selecting the files to search in
- Inserting some text at the beginning of each file
- Replacing multiple lines of text
- Searching in Unicode files
- Replacing in binary files
- Performing operations with the found files
- Undoing a replacement
- Saving search parameters for further use
- Removing private data
- Adding or removing Aba from Explorer context menu
- Integrating Aba with Total Commander
- Integrating Aba with Free Commander
- Integrating Aba with Directory Opus
- Regular Expressions
- Replacement syntax
- Simple replacements
- Complex replacements
- Doing math
- Manipulating with strings
- Checking conditions
- Reading files and inserting file names
- User interface
- Command line
- Troubleshooting
- Glossary
- Version history
- Credits