Instead of local file URLs start with file://.
URL stands for Uniform Resource Locator - which also can point to local files and folders. “I thought a URL was a web address like, not a directory path!” In the results panel of the playground, you now see: file:///Users/sarah/Desktop/ayground Let completeUrl = URL(fileURLWithPath: completePath) Instead, you are going to convert the address into a URL by adding:
MACBOOK FILE MANAGER FULL
While this string describes the full path to this file, it isn’t the best way to handle addresses. So ayground is in the Desktop folder in the sarah folder in the Users folder on the startup drive. After that, every slash delimits a new folder or file. The first slash indicates the root directory, which in this case is your startup disk. Since macOS is Unix-based, this is how Unix (and all its variants) describe file paths. Let completePath = "/Users/sarah/Desktop/ayground"ĬompletePath now contains the address, or path, of this playground file. Once the starting playground is open, delete all the lines except for import Cocoa.Īdd the following line to your playground, but don’t worry about changing the username for now: If you gave it a different name or saved it somewhere else, please rename it and move it before proceeding, or else the code below just won’t work! Note: For this tutorial, the name of the playground must be Files and it must be located on your Desktop. Select your Desktop and click Create to save the playground. Open Xcode and click Get started with a playground in the Welcome to Xcode window, or choose File/New/Playground… Set the name of the playground to Files, make sure the Platform is set to macOS and click Next. Each file has its own address the structure that defines this address is named URL. This means that finding a particular file can be complicated. MacOS uses a hierarchical file system: files & folders inside folders, inside folders.
MACBOOK FILE MANAGER HOW TO
In this tutorial, you’ll learn how to manage directory paths, work with URLs, use common file and folder dialogs, display file and folder information, and much more! Getting Startedįor this tutorial, you’ll start with a playground and move on to an app later once you’ve learned the basics. With files and data spread all over the filesystem, how can your app find out about files and folders, work with file and folder paths, and even read and write data to a file? Your app is stored in the Applications folder, users store documents in their Documents folder, and preferences and support files are stored in the users Library folder. The file system in macOS underlies every app - and the FileManager class has a lot to do with that.