gpt4 book ai didi

objective-c - 如何使用 objective-c 获取ipad目录中的所有文件

转载 作者:太空狗 更新时间:2023-10-30 03:48:05 35 4
gpt4 key购买 nike

我需要获取一个目录下的所有文件,包括所有子目录和每个子目录下的所有文件。在 objective-c 中,我尝试使用这种方法[[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil]

但它只是在目录 filePath 中给我一个目录文件的数组,我无法获取子目录中的所有文件,有人可以帮助我吗??

谢谢

最佳答案

- (void)scanPath:(NSString *) sPath {

BOOL isDir;

[[NSFileManager defaultManager] fileExistsAtPath:sPath isDirectory:&isDir];

if(isDir)
{
NSArray *contentOfDirectory=[[NSFileManager defaultManager] contentsOfDirectoryAtPath:sPath error:NULL];

int contentcount = [contentOfDirectory count];
int i;
for(i=0;i<contentcount;i++)
{
NSString *fileName = [contentOfDirectory objectAtIndex:i];
NSString *path = [sPath stringByAppendingFormat:@"%@%@",@"/",fileName];


if([[NSFileManager defaultManager] isDeletableFileAtPath:path])
{
NSLog(path);
[self scanPath:path];
}
}

}
else
{
NSString *msg=[NSString stringWithFormat:@"%@",sPath];
NSLog(msg);
}
}

你可以调用这个函数来记录目录中的所有文件,希望这对你有所帮助。

关于objective-c - 如何使用 objective-c 获取ipad目录中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9669800/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com