Skip to content

Modern Fs ExpandHome

Paul Squires edited this page Oct 19, 2026 · 2 revisions

Home › Filesystem › Filesystem Library › ExpandHome

ExpandHome

Returns a path with a leading ~ replaced by the user's home folder.

Syntax

ExpandHome( p )

Notes

  • Expands "" and a leading "/" (and "~" on Windows) only. Anything else -- "bob/x", "a/", an empty string -- comes back unchanged.
  • Fails only when p starts with ~ and HomeDir( ) fails.

Examples

#import "std/fs"
using fs

print cbool( ExpandHome( "~/notes.txt" ).ValueOr( "" ) = PathJoin( HomeDir( ).ValueOr( "" ), "notes.txt" ) )    '' true
print ExpandHome( "~bob/x" ).ValueOr( "" )      '' ~bob/x -- other users are not looked up
print ExpandHome( "a/~" ).ValueOr( "" )         '' a/~

Library: Filesystem Library Category: Filesystem Documented under: Directories

Clone this wiki locally