[英]NSFileManager in document folder
i am trying to zip a file into a subfolder in my iphone app. 我正在尝试将文件压缩到我的iPhone应用程序的子文件夹中。
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir = [path objectAtIndex:0];
NSString *storeunzipfiles = [dir stringByAppendingPathComponent:@"/MyFolder"];
if (![[NSFileManager defaultManager] fileExistsAtPath:storeunzipfiles])
[[NSFileManager defaultManager] createDirectoryAtPath:storeunzipfiles attributes:nil]; //Create folder
ok now i created the folder. 好的,现在我创建了文件夹。 What i want to do is to del all the files in the folder before i unzip my file.
我要做的是在解压缩文件之前先删除文件夹中的所有文件。 but i am not getting it.
但我不明白。
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
[filemgr removeItemAtPath: @"/MyFolder" handler: nil];
// warning: 'NSFileManager' may not respond to '-removeItemAtPath:handler:'
}
}
lastly, unzip to subfolder. 最后,解压缩到子文件夹。
if ([zip UnzipFileTo:storeunzipfiles overWrite:YES]) {...
ok i got a warning msg... 好吧,我得到了警告味精...
whats the method to load the files in the subfolder? 在子文件夹中加载文件的方法是什么? is this right?
这是正确的吗?
NSString *docpath = [documentsDirectory stringByAppendingPathComponent:@"/MyFolder/Data.plist"]; ?
thks in advance 提前
There is no -removeItemAtPath:handler:
method. 没有
-removeItemAtPath:handler:
方法。 You want -removeItemAtPath:error:
instead. 您需要
-removeItemAtPath:error:
No, 没有,
You can use method 您可以使用方法
- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error
this will return a NSarray object that contains Name of File contains in given folder. 这将返回一个NSarray对象,该对象包含给定文件夹中包含的文件名。 after that u can remove easily.
之后,您可以轻松移除。 example
例
NSarray *array=[filemanager contentsOfDirectoryAtPath:@"/MyFolder" error:nil];
for(int i=0;i<[array count];i++)
{
[filemanager removeItemAtPath:[@"/MyFolder" stringByAppendingPathComponent:[array objectAtIndex:i]] error:nil];
}
so folder will be empty 因此文件夹将为空
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.