Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Folder in Swift

Tags:

macos

swift

I'm new to swift and I'm not sure how to make a new folder from a string path (or from some kind of File/ NSFile object)

This is on OS X with Cocoa.

like image 407
Will Richardson Avatar asked Jan 03 '15 09:01

Will Richardson


People also ask

How do I create a directory in Swift?

Creating a new directory A new directory is created in Swift using the createDirectory(atPath:) instance method of the FileManager class. It is once again passing through the pathname of the new directory as an argument and returning a Boolean true or false result.

How do I create a folder in Xcode?

You can create a new group, with its own folder, directly in Xcode, but it's not at all obvious. Instead of choosing 'New Group', choose 'Add Files to “<Project>”'. Then, in the file picker dialog, click the New Folder button or press Command-Shift-N and type the name of the new folder/group.

What is document directory in Swift?

In the iOS application we have to store files, images, audios, videos. We can do it by creating folder in Document directory. Document directory stores user data to the given path in the apps. You can read apps data from the path of document directory.


1 Answers

My understanding is that you are trying to create a directory programmatically using swift. The code given below does the same.

    var err: NSErrorPointer = nil
    let manager = NSFileManager.defaultManager()
    manager.createDirectoryAtPath("/Users/abc/Desktop/swiftDir", withIntermediateDirectories: true, attributes: nil, error: err)
like image 178
Seema Kadavan Avatar answered Sep 20 '22 10:09

Seema Kadavan