iOS中判断一个文件夹是否存在

- (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);

    }

}

你可能感兴趣的:(ios)