//
// main.m
// file
//
// Created by 裴烨烽 on 14-4-6.
// Copyright (c) 2014年 _______Smart_______. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
// 创建文件操作对象
// 当前文件路径
NSFileManager *fm=[NSFileManager defaultManager]; //文件操作对象
NSLog(@"当前目录= %@",[fm currentDirectoryPath]);
// 判断文件是否存在
NSString *fPathName=@"/Foundation/Code/testFile";// 不区分大小写
if([fm fileExistsAtPath:fPathName]==NO)
{
NSLog(@"文件(%@)不存在",fPathName);
}
// 复制文件
if([fm copyItemAtPath:fPathName toPath:@"newFile" error:NULL]==NO)
{
NSLog(@"复制文件失败!");
}
// 判断文件内容是否相等
if([fm contentsEqualAtPath:fPathName andPath:@"newFile"]==NO)
{
NSLog(@"文件不相等");
}
// 重命名文件名称
if([fm moveItemAtPath:@"newFile" toPath:@"newFile2" error:NULL]==NO)
{
NSLog(@"文件重命名失败!");
}
// 打印文件内容
NSLog(@"Current:%@",[NSString stringWithContentsOfFile:@"newFile2" encoding:NSUTF8StringEncoding error:NULL]);
// 读取文件属性(字典属性
NSDictionary *attr; // 属性
if((attr = [fm attributesOfItemAtPath:@"newFile2" error:NULL]) == nil){
{
NSLog(@"无法获取文件属性!");
}
NSLog(@"文件大小为=%llu bytes",[[attr objectForKey:NSFileSize] unsignedLongLongValue]);
// 删除文件
if([fm removeItemAtPath:@"newFile2" error:NULL]==NO)
{
NSLog(@"文件删除失败");
}
NSLog(@"所有操作成功");
}
return 0;
}
}