Created
August 2, 2012 16:14
-
-
Save flyfire/3238302 to your computer and use it in GitHub Desktop.
Objective-C:NSProcessInfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main(int argc, char const *argv[]) | |
{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
NSFileManager *fm; | |
NSString *src,*dst; | |
BOOL isDir; | |
NSProcessInfo *proc = [NSProcessInfo processInfo]; | |
NSArray *args = [proc arguments]; | |
fm = [NSFileManager defaultManager]; | |
if ([args count] != 3) | |
{ | |
NSLog(@"Usage:%@ src dst",[proc processName]); | |
return 1; | |
} | |
src = [args objectAtIndex:1]; | |
dst = [args objectAtIndex:2]; | |
if ([fm isReadableFileAtPath:src] == NO) | |
{ | |
NSLog(@"cant read %@",src); | |
return 2; | |
} | |
[fm fileExistsAtPath:dst isDirectory: &isDir]; | |
if (isDir == YES) | |
{ | |
dst = [dst stringByAppendingPathComponent:[src lastPathComponent]]; | |
} | |
[fm removeFileAtPath:dst handler:nil]; | |
if ([fm copyPath:src toPath:dst handler:nil] == NO) | |
{ | |
NSLog(@"Copy failed."); | |
return 3; | |
} | |
NSLog(@"Copy of %@ to %@ succeeded!",src,dst); | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment