//
// main.m
// OC6_目录及文件的创建
//
// Created by zhangxueming on 15/6/19.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) {
@autoreleasepool {
NSFileManager *fm = [NSFileManager defaultManager];
//创建目录
//- (BOOL)createDirectoryAtPath:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error
//path: 创建目录的路径,包含创建目录的目录名
//createIntermediates: 是否创建中间目录
//attributes: 目录属性(NSDictionary) NSError *error= nil;
BOOL ret = [fm createDirectoryAtPath:@"/Users/zhangxueming/Desktop/Test/qianfeng/ios/newdic" withIntermediateDirectories:YES attributes:nil error:&error];
if (ret) {
NSLog(@"目录创建成功");
}
else
{
NSLog(@"目录创建失败 %@", error);
} //创建文件
//- (BOOL)createFileAtPath:(NSString *)path contents:(NSData *)data attributes:(NSDictionary *)attr;
//path: 文件的路径(包含文件名)
//data: 文件的内容
//attr: 文件的属性
ret = [fm createFileAtPath:@"/Users/zhangxueming/Desktop/Test/hello.c" contents:nil attributes:nil];
if(ret)
{
NSLog(@"文件创建成功");
}
else{
NSLog(@"文件创建失败");
} }
return ;
}