source.getFileDirectory() Code Wizard Function
Overview
QIE adds a new Code Wizard function under Source -> [selected format] -> File named Get File Directory. In scripts, this function is available as:
source.getFileDirectory()
It returns the source-relative directory path associated with the current source file, using / as the separator, when Include All Subdirectories is enabled.
Source-Relative Example:
- Source 'Path' set to: /incoming/files/source-root/
- Include All Subdirectories enabled
- File found in: /incoming/files/source-root/sub1/sub2/
- source-relative path: sub1/sub2
- So source.getFileDirectory() returns: sub1/sub2
Return Value
- Returns the source-relative directory path for the current file
- Returns empty string ("") when the file is in the source root
Example return values:
""
"orders/2026/03"
"site-a/lab-results"
When to Use It
Use source.getFileDirectory() when your script needs to:
- Route based on the subfolder the file came from
- Rebuild part of the original folder structure in an archive or destination path
- Add source folder details to logs or notifications
Example
var fileDirectory = source.getFileDirectory();
var archivePath = "/archive";
if (fileDirectory !== "") {
archivePath += "/" + fileDirectory;
}
// archivePath is now either "/archive" or something like "/archive/orders/2026/03"
Relationship to Recursive Sources
This function is only useful when Include All Subdirectories is enabled on a File, Network Share, or FTP source. When Include All Subdirectories is disabled it return an empty string ("").
For example, if the source file arrives in the source-relative path as:
[source path]/orders/2026/03/input.hl7
then:
source.getFileDirectory()
returns:
orders/2026/03
If the file is in the root of the source path, the function returns an empty string.
Related Functions
This function works well with the other file Code Wizard functions:
- source.getFileName(): The filename including the extension.
- source.getFileNameWithoutExt(): The filename without the extension.
- source.getFileExt(): The file extension only.
Together, these functions let you build file-aware routing and naming logic without manually splitting strings.
Also see these related questions:
What source metadata node tags are available in QIE?
Can QIE do recursive subdirectory scanning for File, Network Share, and FTP Sources?