文件夹操作

2016-11-04  本文已影响11人  PZcoder

1.基础类方法:判断是否有此文件(fileName)

/*
 @abstract 检查Documents里是否有此文件
 */
+ (BOOL)fileExistsAtPath:(NSString *)fileName
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *DocumentsPath = [documentsDirectory stringByAppendingPathComponent:fileName];

    return [fileManager fileExistsAtPath:DocumentsPath];
}

2.基础类方法:根据文件名(fileName)找到文件路径

+ (NSString *)getFilePath:(NSString *)fileName
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *DocumentsPath = [documentsDirectory stringByAppendingPathComponent:fileName];
    
    return DocumentsPath;
}


上一篇下一篇

猜你喜欢

热点阅读