如何在iPhone中查找文档目录中的内容
我想知道目录中的内容,无论是其文档还是任何其他目录。 如果有一个或多个文件,我需要这些文件名。 实际上我正在文档目录中创建导出目录.. 如果导出为空,那么我将 zip 文件从主包复制到导出文件夹,
但以下代码不起作用。虽然导出是空的,但它不会进入 if 块..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);
i want to know the contents in a directory either its documents or any other.
if there is a file or more than one i need those file names.
actually i am creating the export directory in documents directory..
and if export is empty then i am copying the zip file from main bundle to export folder
but the following code is not working. though the export is empty its not going in to that if block..r there any hidden files..? and in the last for loop its not doing any thing.
how to do this.
please help me out
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
斯威夫特 4 版本:
Swift 4 version: