我想知道目录中的内容,无论是其文档还是其他任何内容。如果有一个或多个文件,我需要这些文件名。实际上我正在文档目录中创建导出目录。如果导出为空,那么我正在将 zip 文件从主包复制到导出文件夹
但以下代码不起作用。虽然导出是空的,但如果阻止..r 有任何隐藏文件..?在最后一个 for 循环中它没有做任何事情。
这该怎么做。
请帮帮我
self.fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
self.documentsDir = [paths objectAtIndex:0];
//creating folder 'export' to recieve the file from iTunes
NSString *srcFilePath = [NSString stringWithFormat:@"%@/export", self.documentsDir];
[fileManager createDirectoryAtPath:srcFilePath
withIntermediateDirectories:NO
attributes:nil
error:nil];
//copying the zip file into exprort from bundle if export is empty
if(![fileManager fileExistsAtPath:srcFilePath]) {
NSLog(@"File exists at path: %@", srcFilePath);
NSString *resZipfile = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"zip"
inDirectory:@"pckg"];
NSLog(@"zip file path ...%@", resZipfile);
NSData *mainBundleFile = [NSData dataWithContentsOfFile:resZipfile];
[[NSFileManager defaultManager] createFileAtPath:srcFilePath
contents:mainBundleFile
attributes:nil];
}
NSString *eachPath;
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:srcFilePath];
for(eachPath in dirEnum) NSLog(@"FILE: %@", eachPath);