Show Folder's Contents in Finder Using Swift

Show folder's contents in finder using Swift

Use the selectFile method and pass nil as first argument and the path to the folder to be shown as second argument.

NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: "/Users/")

Open directory in finder?

You should use FileManager urls for applicationDirectory at the systemDomainMask and append your path component to the url returned. Then all you need is use open method and pass your directory url:

if let inspirationsDirectory = FileManager.default.urls(for: .applicationDirectory, in: .systemDomainMask).first?.appendingPathComponent("Inspirations", isDirectory: true){
NSWorkspace.shared.open(inspirationsDirectory)
}

Launch Finder window with specific files selected

Objective-C version:

NSArray *fileURLs = [NSArray arrayWithObjects:fileURL1, /* ... */ nil];
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];

How do I programmatically open a folder in the Finder without selecting anything?

It suffices to ask the workspace to open the folder as a file, because the Finder is the default app for folders. For example:

NSWorkspace.shared.open(
URL(
fileURLWithPath: "/System/Library/CoreServices",
isDirectory: true
)
)

(The isDirectory parameter is optional but passing it saves a system call.)

How can I display my App documents in the Files app for iPhone

If you would like to expose your App document files inside Apple's Files App you need to include the "Supports Document Browser" key in your info plist file and set it to YES:

Sample Image

Created Group folder is not visible in show in finder on xcode

No. You have to track (create) the folders both in xocde and in finder manually.

You can create folder in finder and then can import that folder in xcode.

The folder you make in xcode is identical to the finder.

So, the folder that you will make in finder, will be the original tree structure for your project.



Related Topics



Leave a reply



Submit