#import <Foundation/Foundation.h> #define getb(x) x==0? @"失败" : @"成功" int main(int argc, const char * argv[]) { @autoreleasepool { NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES); NSString* thepath = [paths lastObject]; NSLog(@"桌面目录:%@", thepath); thepath = [thepath stringByAppendingPathComponent:@"testfolder"]; NSLog(@"桌面目录:%@", thepath); NSFileManager* fm = [NSFileManager defaultManager]; BOOL b = [fm createDirectoryAtPath:thepath withIntermediateDirectories:NO attributes:nil error:nil]; NSLog(@"添加文件夹%@",getb(b)); thepath= [thepath stringByAppendingPathComponent:@"a.txt"]; NSData * data = [@"爱是恒久远" dataUsingEncoding:NSUTF8StringEncoding ]; b = [fm createFileAtPath:thepath contents:data attributes:nil]; NSLog(@"添加文件%@",getb(b)); } return 0; }
在MAC桌面上新建文件夹和文件,布布扣,bubuko.com
原文:http://blog.csdn.net/chairwon/article/details/22747643