extension ';' PATH
Macro
Summary
Extract the file extension from a file path, returning the part after the last dot in the filename.
Syntax
${extension;<path>}
Parameters
- path: File path from which to extract the extension
Behavior
The macro:
- Normalizes the path (handles different path separators)
- Extracts the last segment (filename) from the path
- Returns the part after the last
.in the filename - Returns an empty string if no extension is present
The extension is returned without the leading dot.
Examples
# Extract extension from file path
${extension;myfile.txt} # Returns: txt
${extension;/path/to/document.pdf} # Returns: pdf
${extension;archive.tar.gz} # Returns: gz (only last extension)
# No extension cases
${extension;README} # Returns: (empty)
${extension;/path/to/folder/} # Returns: (empty)
# Multiple dots
${extension;my.file.name.java} # Returns: java
# Original examples
${extension;abcdef.def} # Returns: def
${extension;/foo.bar/abcdefxyz.def} # Returns: def
${extension;abcdefxyz} # Returns: (empty)
${extension;/foo.bar/abcdefxyz} # Returns: (empty)
# Used with other macros
-include ${extension;${workspace}/.project} == project
Use Cases
- File Type Detection: Determine the type of file being processed
- Conditional Logic: Apply different processing based on file extension
- File Filtering: Select files based on their extensions
- Path Construction: Build new paths with modified extensions
Related Macros
- basenameext - Extract basename, optionally removing an extension
- stem - Get filename without extension
- basename - Get the last path segment
See test cases in MacroTestsForDocsExamples.java
