读书人

IOS中调用NSFileManager的copyItemAtP

发布时间: 2013-01-27 13:55:24 作者: rapoo

IOS中调用NSFileManager的copyItemAtPath:toPath:error:复制文件之后无法找到
NSBundle *bundle=[NSBundle mainBundle];

NSString *mp4path=[bundle pathForResource:@"thecopyfile" ofType:@"mp4"];

NSString*filepath=[NSHomeDirectory() stringByAppendingPathComponent:@"Caches/A"];

NSFileManager *fileManager=[NSFileManager defaultManager];

[fileManager copyItemAtPath:mp4path toPath:filepath error:&error];


然后我再去获取A文件夹中的所有文件
for (NSString *filename in [fileManager enumeratorAtPath:filepath]) {
NSLog(@"%@",filename);
}

但是却找不到开始复制过去的那个thecopyfile.mp4文件
[解决办法]
首先copyItemAtPath里面的filepath不能是个文件夹路径。必须是个文件路径如:a/temp.mp4。
其次取a文件夹下面的文件不用enumeratorAtPath,而是contentsOfDirectoryAtPath,这个path才是路径,不能写成了文件的地址。

读书人网 >Iphone

热点推荐