Skip to content

Instantly share code, notes, and snippets.

@flyfire
Created August 2, 2012 16:14
Show Gist options
  • Save flyfire/3238302 to your computer and use it in GitHub Desktop.
Save flyfire/3238302 to your computer and use it in GitHub Desktop.
Objective-C:NSProcessInfo
#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