expand vars
Paths with $HOME and %USERPROFILE% that work on any machine
- expanded path
Basic data handling: PathExpandVars ("expand vars") is the node that stops you hardcoding your username into every path. You know the pattern - you write a workflow that reads or writes a file in C:\Users\YourName\Pictures\... and it works great on your box, then you hand the workflow to a friend (or run it on a second machine) and everything breaks because their username is different. This node is the fix: it expands environment variables inside a path string.
Give it $HOME/stuff or ${HOME}/stuff on Linux/macOS, or %USERPROFILE%\stuff on Windows, and it returns the fully resolved path with the variable replaced. It's a thin wrapper around Python's os.path.expandvars() - literally a one-liner in the source - but it turns a hardcoded path into a portable one.
Why you'd actually use it
Two main cases. First, portability: put the node between a string input and anything that touches disk, and a path written as $HOME/models works identically on Linux, macOS, and (with %USERPROFILE%) Windows. Second, tidiness: ComfyUI's input and output directories live wherever you installed it, but your other stuff - a shared reference image folder, a dataset you're generating into - might live anywhere. Referencing it via an env var keeps the workflow readable instead of burying a giant absolute path in a widget.
Inputs and outputs
- path (STRING, default
"") - the path with variables still in it. - expanded path (STRING) - the same path with every environment variable replaced. Wire it into any node that wants a path.
Installing it
Part of the Basic data handling pack, no extra dependencies. ComfyUI Manager → search "Basic data handling" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Then restart. No models to download, nothing to pip install - this pack deliberately stays dependency-free.
Gotchas
The big one is cross-platform syntax, and it's a real trap:
- Unix style (
$HOME,${VAR}) is what works on Linux/macOS. On Windows,os.path.expandvarswon't touch$VAR- Windows uses%VAR%syntax. - If a variable isn't set, the node leaves the
$VAR/%VAR%text in place rather than erroring. So a typo won't crash your workflow; it'll silently hand you an unresolved path downstream. Worth remembering when a path "mysteriously" doesn't resolve. - It only expands environment variables - it does not expand
~for home. If you're typing~/models, that tilde will pass through unchanged. That's a job foros.path.expanduser, and it's not what this node does.
One small aside: because $ and % are the trigger characters, paths that legitimately contain either can get mangled. Rare in practice, but if you're ever feeding in something weird like a literal $ in a filename, expand vars is where it'll bite. For 99% of workflows - "give me the user's home folder without asking who they are" - this is exactly the right tool.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| path | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| expanded path | STRING | — |