How to get user home directory path (Users/”user name”) without knowing the username in Swift3

You can use FileManager property homeDirectoryForCurrentUser

let homeDirURL = FileManager.default.homeDirectoryForCurrentUser

If you need it to work with earlier OS versions than 10.12 you can use

let homeDirURL = URL(fileURLWithPath: NSHomeDirectory())

print(homeDirURL.path)

Leave a Comment