#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桌面上新建文件夹和文件
最新推荐文章于 2025-02-12 15:58:15 发布