diff --git a/appshell/appshell_extensions_mac.mm b/appshell/appshell_extensions_mac.mm index 373bdd0d6..d86051718 100644 --- a/appshell/appshell_extensions_mac.mm +++ b/appshell/appshell_extensions_mac.mm @@ -605,7 +605,17 @@ - (void) timeoutTimer:(NSTimer*)timer int32 ShowFolderInOSWindow(ExtensionString pathname) { NSString *filepath = [NSString stringWithUTF8String:pathname.c_str()]; - [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:[NSArray arrayWithObject: [NSURL fileURLWithPath: filepath]]]; + BOOL isDirectory; + + if (![[NSFileManager defaultManager] fileExistsAtPath:filepath isDirectory:&isDirectory]) { + return ERR_NOT_FOUND; + } + + if (isDirectory) { + [[NSWorkspace sharedWorkspace] openFile:filepath]; + } else { + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:[NSArray arrayWithObject: [NSURL fileURLWithPath: filepath]]]; + } return NO_ERROR; } diff --git a/appshell/appshell_extensions_win.cpp b/appshell/appshell_extensions_win.cpp index e3ecf7412..1a626ec5b 100644 --- a/appshell/appshell_extensions_win.cpp +++ b/appshell/appshell_extensions_win.cpp @@ -811,7 +811,26 @@ time_t FiletimeToTime(FILETIME const& ft) { } int32 ShowFolderInOSWindow(ExtensionString pathname) { - ShellExecute(NULL, L"open", pathname.c_str(), NULL, NULL, SW_SHOWDEFAULT); + ConvertToNativePath(pathname); + + DWORD dwAttr = GetFileAttributes(pathname.c_str()); + if (dwAttr == INVALID_FILE_ATTRIBUTES) { + return ConvertWinErrorCode(GetLastError()); + } + + if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0) { + // Folder: open it directly, with nothing selected inside + ShellExecute(NULL, L"open", pathname.c_str(), NULL, NULL, SW_SHOWDEFAULT); + + } else { + // File: open its containing folder with this file selected + ITEMIDLIST *pidl = ILCreateFromPath(pathname.c_str()); + if (pidl) { + SHOpenFolderAndSelectItems(pidl,0,0,0); + ILFree(pidl); + } + } + return NO_ERROR; }