Files · SWIFT RECIPE

Get the current directory

Find the working directory of the running process.

main.swift
import Foundation
let path = FileManager.default.currentDirectoryPath
print(URL(fileURLWithPath: path, isDirectory: true).path)

How it works

The working directory is a process setting. It is not necessarily the executable location, the app bundle, or a documents folder. Use URL-based APIs when passing it to filesystem operations.

Keep in mind

In an iOS app, use FileManager URLs for your app’s sandbox directories.

Read the Swift language reference