[NSFileManager defaultManager]有这么一个api
- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(nullable BOOL *)isDirectory
isDirectory是一个指针
说明如下:
Upon return, contains YES if path is a directory or if the final path element is a symbolic link that points to a directoryotherwise, contains NO. If path doesn’t exist, this value is undefined upon return. Pass NULL if you do not need this information.
就是说传入一个bool类型的指针,执行改方法后这个参数的值是yes的话就是路径,反之是文件。
用法如下:
BOOL isDir = NO[[NSFileManager defaultManager] fileExistsAtPath:allPath isDirectory:&isDir]
if(isDir)//是文件夹
{
}
- (void)createFileDirectories{
// 判断存放音频、视频的文件夹是否存在,不存在则创建对应文件夹
NSFileManager *fileManager = [NSFileManagerdefaultManager]
BOOL isDir = FALSE
BOOL isDirExist = [fileManager fileExistsAtPath:DOCUMENTS_FOLDER_AUDIOisDirectory:&isDir]
if(!(isDirExist &&isDir))
{
BOOL bCreateDir = [fileManager createDirectoryAtPath:DOCUMENTS_FOLDER_AUDIOwithIntermediateDirectories:YESattributes:nilerror:nil]
if(!bCreateDir){
NSLog(@"Create Audio Directory Failed.")
}
NSLog(@"%@",DOCUMENTS_FOLDER_AUDIO)
}
isDir = FALSE
isDirExist = [fileManager fileExistsAtPath:DOCUMENTS_FOLDER_VEDIOisDirectory:&isDir]
if(!(isDirExist &&isDir)){
BOOL bCreateDir = [fileManager createDirectoryAtPath:DOCUMENTS_FOLDER_VEDIOwithIntermediateDirectories:YESattributes:nilerror:nil]
if(!bCreateDir){
NSLog(@"Create Audio Directory Failed.")
}
NSLog(@"%@",DOCUMENTS_FOLDER_VEDIO)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)