Reputation: 235
i am trying to zip a file into a subfolder in my iphone app.
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
Upvotes: 0
Views: 1301
Reputation: 7
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. 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
Upvotes: 0
Reputation: 523154
There is no -removeItemAtPath:handler:
method. You want -removeItemAtPath:error:
instead.
Upvotes: 1