3 Replies
      Latest reply on Jun 17, 2019 2:08 PM by gumbright
      gumbright Level 1 Level 1 (0 points)

        I am trying to use FileManager contentsOfDirectory(at:,includingPropertiesForKeys:,options:) to get the contents of the root level of an AFP mounted volume.  The call throws an exception.  Volume is mounted and readily accessible in Finder.

        The url content is "file:///Volumes/incoming/"

        The error received is The file “incoming” couldn’t be opened because you don’t have permission to view it.

        Here is the relevant code:


                do {
                    let contents = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles,.skipsPackageDescendants,.skipsSubdirectoryDescendants])
                    result = contents
                catch let error as NSError {

        Is there something else I need to be doing?  I have not done MacOS dev for a while so I am guessing I am missing something simple. Some setting in the info.plist required now or something along those lines?

        • Re: Cannot get contentsOfDirectory on AFP volume (MacOS)
          gumbright Level 1 Level 1 (0 points)

          I found it. App Sandboxing is the issue.  Turning that off allowed me access.  But if I understand correctly, if I wanted my app to be available in the Mac App Store, it must be sandboxed.  Is there any middle ground here?  The app's purpose requires full access to the file system (read and potentially delete).

            • Re: Cannot get contentsOfDirectory on AFP volume (MacOS)
              eskimo Apple Staff Apple Staff (13,015 points)

              The sandbox does not prevent you from accessing files on a volume, it prevents you from accessing files without the user’s explicit consent.  The user gives that consent by either choosing the file in one of the standard open or save dialogs, or by dragging it into your app.  If you want to be compatible with the Mac App Store, you have to structure your app to use one of those techniques.  For example, based on the volume name (Incoming) it looks like your app is monitoring a volume for activity, kinda like a dropbox.  In that case your best option is to restructure your UI so that you don’t hard code the dropbox, but instead ask the user to choose it using a standard open dialog.  Once the user has chosen it, you will then have access to it.

              Share and Enjoy

              Quinn “The Eskimo!”
              Apple Developer Relations, Developer Technical Support, Core OS/Hardware
              let myEmail = "eskimo" + "1" + "@apple.com"