Advertisement
sophtwhere

NSFileManager+openFinderFolder.m

Oct 28th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  NSFileManager+openFinderFolder.m
  3. //
  4. //  Created by Jonathan Annett on 28/10/13.
  5. //  Copyright (c) 2013 Sophtwhere. All rights reserved.
  6. //
  7.  
  8. #import "NSFileManager+openFinderFolder.h"
  9.  
  10.  
  11. NSString *openInFinderFolderFormat = @"/usr/bin/open \"%@\"" ;
  12. NSString *revealInFinderFormat     = @"/usr/bin/open -R \"%@\"";
  13.  
  14.  
  15. @implementation NSFileManager (openFinderFolder)
  16.  
  17. -(void) openFinderFolderAtPath:(NSString*) path {
  18. #if TARGET_IPHONE_SIMULATOR
  19.     BOOL isDirectory = NO;
  20.     if ([self fileExistsAtPath:path isDirectory:&isDirectory]) {
  21.         if (isDirectory) {
  22.             NSString *openCommand = [NSString stringWithFormat:openInFinderFolderFormat, path];
  23.             system([openCommand fileSystemRepresentation]);
  24.         }
  25.     }
  26. #endif
  27. }
  28.  
  29. -(void) revealItemInFinder:(NSString*) path {
  30. #if TARGET_IPHONE_SIMULATOR
  31.     BOOL isDirectory = NO;
  32.     if ([self fileExistsAtPath:path isDirectory:&isDirectory]) {
  33.         NSString *openCommandFormat = isDirectory ? openInFinderFolderFormat : revealInFinderFormat;
  34.         NSString *openCommand = [NSString stringWithFormat:openCommandFormat, path];
  35.         system([openCommand fileSystemRepresentation]);
  36.     }
  37. #endif
  38. }
  39.  
  40. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement