QMFileManager.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // QMFileManager.m
  3. // IMSDK-OC
  4. //
  5. // Created by HCF on 16/8/11.
  6. // Copyright © 2016年 HCF. All rights reserved.
  7. //
  8. #import "QMFileManager.h"
  9. @interface QMFileManager ()
  10. @property (nonatomic)NSFileManager *fileManager;
  11. @end
  12. @implementation QMFileManager
  13. + (BOOL)createFolder: (NSString *)folderPath {
  14. NSString * path = [NSString stringWithFormat:@"%@/%@", kDOCUMENTS, folderPath];
  15. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  16. NSError *error = nil;
  17. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  18. if (error) {
  19. return NO;
  20. }else {
  21. return YES;
  22. }
  23. }else {
  24. return NO;
  25. }
  26. }
  27. + (NSArray *)getFileNames: (NSString *)folderPath {
  28. NSString * path = [NSString stringWithFormat:@"%@/%@", kDOCUMENTS, folderPath];
  29. return [[NSFileManager defaultManager] subpathsAtPath:path];
  30. }
  31. + (BOOL)fileIsExsited: (NSString *)filePath {
  32. NSString *path = [NSString stringWithFormat:@"%@/%@", kDOCUMENTS, filePath];
  33. return [[NSFileManager defaultManager] fileExistsAtPath:path];
  34. }
  35. + (NSDictionary *)getFileAttributes: (NSString *)filePath {
  36. NSString *path = [NSString stringWithFormat:@"%@/%@", kDOCUMENTS, filePath];
  37. if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
  38. NSError *error = nil;
  39. return [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
  40. }else {
  41. return nil;
  42. }
  43. }
  44. + (NSString *)writeDictionary: (NSDictionary *)dict toFile: (NSString *)filePath {
  45. NSString *path = [NSString stringWithFormat:@"%@/%@", kDOCUMENTS, filePath];
  46. BOOL success = [dict writeToFile:path atomically:YES];
  47. if (success) {
  48. return path;
  49. }else {
  50. return nil;
  51. }
  52. }
  53. + (NSMutableDictionary *)readDictionary: (NSString *)filePath {
  54. NSString *path = [NSString stringWithFormat:@"%@/%@", kDOCUMENTS, filePath];
  55. return [NSMutableDictionary dictionaryWithContentsOfFile:path];
  56. }
  57. @end