JohnSundell / Files

A nicer way to handle files & folders in Swift
MIT License
2.53k stars 182 forks source link

Documents Directory iOS #57

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi,

There is API for the docs directory, but it's not public. Any reason for this?

The 'home' API seems to work as follows

let home = Folder.home.path
macOS: /Users/robertnash/
iOS: /Users/robertnash/Library/Developer/CoreSimulator/Devices/91BA8C3F-9B72-42AB-89D1-6401B183E5EB/data/Containers/Data/Application/

The docs directory is a little deeper.

let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
macOS: file:///Users/robertnash/Documents/
iOS: file:///Users/robertnash/Library/Developer/CoreSimulator/Devices/91BA8C3F-9B72-42AB-89D1-6401B183E5EB/data/Containers/Data/Application/A568FA48-5C29-4368-9123-008EAC5DA331/Documents/

Would be good to get the applicationSupportDirectory too

let storeDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
macOS: file:///Users/robertnash/Library/Application%20Support/
iOS: file:///Users/robertnash/Library/Developer/CoreSimulator/Devices/91BA8C3F-9B72-42AB-89D1-6401B183E5EB/data/Containers/Data/Application/A568FA48-5C29-4368-9123-008EAC5DA331/Library/Application Support/
ghost commented 6 years ago

Ah ha!

let system = FileSystem()
let path = system.homeFolder.path
print("home: \(path)")

Output

home: /Users/robertnash/Library/Developer/CoreSimulator/Devices/91BA8C3F-9B72-42AB-89D1-6401B183E5EB/data/Containers/Data/Application/84D3A5EB-7DFE-4E6B-8E06-6784588CF3FA/

Then

let folder = try! Folder(path: home)
let documents = try! folder.subfolder(named: "Documents")
print("doc: \(documents.path)")

Output

doc: /Users/robertnash/Library/Developer/CoreSimulator/Devices/91BA8C3F-9B72-42AB-89D1-6401B183E5EB/data/Containers/Data/Application/F5FBDBEE-BDA6-4420-92BE-4D17C355C056/Documents/