0

I need check files in directory exists and can be open, but my FileManager.default.fileExists(atPath: <#url_from_uidocumentbrowservc#>) return false. I can't get list of items in selected directory, I can't check my item exists or not.

And one more thing, I want to know how many items are contained in root directory from selected item. For example I choose project file and want to check how many items are contained in project directory then use this files like project dependencies.

Looks to code:

func presentDocument(at documentURL: URL) throws {
   let rootDirectoryURL = documentURL.deletingLastPathComponent()
   let items = try FileManager.default.contentsOfDirectory(at: rootDirectoryURL, 
                                      includingPropertiesForKeys: [], 
                                      options: []) // Return error `permission denied`
   ... other code for init document

}

P.S. URL.startAccessingSecurityScopedResource doesn't work too.

Brooketa
  • 352
  • 2
  • 9

1 Answers1

0

If you want to know which files are saved in the root directory:

 override func viewDidLoad() {
    super.viewDidLoad()

 let fileName = getDocumentsDirectory().appendingPathComponent("fileNameSave")
    print(fileName)
    // Name of saved path

    do {
        try  .write(to: fileNameZip)
    } catch {
        print("error")
    }
}


func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return paths[0]
}
Hiền Đỗ
  • 526
  • 6
  • 14
  • I mean, than I use UIDocumentBrowserViewController like data source of documents. When I get document, I want know how many items contains in root directory selected document. – Vladislav Prusakov Jan 04 '19 at 23:21
  • maybe I have misunderstood your idea. Your problem I have never tried before , and I have just learned through ... https://developer.apple.com/documentation/uikit/view_controllers/adding_a_document_browser_to_your_app/presenting_selected_documents – Hiền Đỗ Jan 07 '19 at 03:16