tags:

views:

71

answers:

2

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

+4  A: 

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];
bbum
+1  A: 

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

[[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.)

Peter Hosey