0

我正在尝试将文件压缩到我的 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

好的,现在我创建了文件夹。我想做的是在解压缩文件之前删除文件夹中的所有文件。但我不明白。

        NSFileManager *filemgr;


           filemgr = [NSFileManager defaultManager];

           [filemgr removeItemAtPath: @"/MyFolder" handler: nil];

   // warning: 'NSFileManager' may not respond to '-removeItemAtPath:handler:'

      }     

      }

最后解压到子文件夹。

   if ([zip UnzipFileTo:storeunzipfiles overWrite:YES]) {...

好的,我收到一条警告消息...

加载子文件夹中文件的方法是什么?这是正确的吗?

NSString *docpath = [documentsDirectory stringByAppendingPathComponent:@"/MyFolder/Data.plist"];     ?

提前谢谢

4

2 回答 2

1

没有-removeItemAtPath:handler:方法。你想要-removeItemAtPath:error:

于 2010-09-05T19:50:29.277 回答
0

不,

你可以使用方法

- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error

这将返回一个 NSarray 对象,该对象包含给定文件夹中包含的文件名。之后你可以轻松删除。例子

NSarray *array=[filemanager contentsOfDirectoryAtPath:@"/MyFolder" error:nil];
for(int i=0;i<[array count];i++)
{
    [filemanager removeItemAtPath:[@"/MyFolder" stringByAppendingPathComponent:[array objectAtIndex:i]] error:nil];
}

所以文件夹将为空

于 2010-09-05T19:54:27.610 回答