Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a folder?

Tags:

cocoa

After save a file I want to open the folder of saved file. How do I do that? Thank you very much!

like image 773
jin Avatar asked Jan 04 '10 06:01

jin


People also ask

How do I open a folder on my computer?

Open the Start menu and type “File Explorer.” Find File Explorer pinned to the taskbar. Right-click a folder and select Open. Some folders already exist in File Explorer, such as Documents, Desktop, and Downloads.

What is the shortcut to open a folder?

Right-click your folder (not the parent one) and select Show More Options > Send To > Desktop (Create Shortcut). This will place your folder's shortcut on your desktop. Access your desktop by pressing Windows+D. On the desktop, find your folder's shortcut.

How do I get to my folders?

Just open it up to browse any area of your local storage or a connected Drive account; you can either use the file type icons at the top of the screen or, if you want to look folder by folder, tap the three-dot menu icon in the upper-right corner and select "Show internal storage" — then tap the three-line menu icon in ...


2 Answers

If I understand your question, you want to open the folder into which something was saved in the Finder?

This should do the trick -- it assumes that you have a reference to the savePanel.

NSURL *fileURL = [savePanel URL];
NSURL *folderURL = [fileURL URLByDeletingLastPathComponent];
[[NSWorkspace sharedWorkspace] openURL: folderURL]; 

If you are starting with an NSString containing the path, then start with:

NSURL *fileURL = [NSURL fileURLWithPath: stringContainingPath];
like image 195
bbum Avatar answered Sep 21 '22 19:09

bbum


Even better would be to not just open the folder, but have the saved file selected. NSWorkspace can do that for you:

[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:
   @[ URLToSavedFile ]];

The argument is an array of URLs, so if you have only one file you want to reveal, you simply pass an array of one object.

If, for some reason, you're targeting a version of Mac OS X older than 10.6, you'd use the older path-based method instead:

[[NSWorkspace sharedWorkspace] selectFile:pathToSavedFile 
                 inFileViewerRootedAtPath:@""];

(You want to pass an empty string for the second argument so that the Finder will reuse an existing Finder window for the folder, if there is one.)

like image 23
Peter Hosey Avatar answered Sep 20 '22 19:09

Peter Hosey