Create a folder inside documents folder in iOS apps

后端 未结 9 1058
一生所求
一生所求 2020-11-28 17:51

I just want to create new folders in the documents folder of my iPhone app.

Does anybody know how to do that?

Appreciate your help!

9条回答
  •  天涯浪人
    2020-11-28 18:30

    Swift 3 Solution:

    private func createImagesFolder() {
            // path to documents directory
            let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
            if let documentDirectoryPath = documentDirectoryPath {
                // create the custom folder path
                let imagesDirectoryPath = documentDirectoryPath.appending("/images")
                let fileManager = FileManager.default
                if !fileManager.fileExists(atPath: imagesDirectoryPath) {
                    do {
                        try fileManager.createDirectory(atPath: imagesDirectoryPath,
                                                        withIntermediateDirectories: false,
                                                        attributes: nil)
                    } catch {
                        print("Error creating images folder in documents dir: \(error)")
                    }
                }
            }
        }
    

提交回复
热议问题