Created
July 12, 2014 09:23
-
-
Save GeneralD/622cc517ee4ee680dd05 to your computer and use it in GitHub Desktop.
Objective-C唯一のiOSファイルパスライブラリ、YKFileの説明書 ref: http://qiita.com/GeneralD/items/b8bd37b1f698ee98fe58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pod "YKFile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YKFile *file = [YKFile documentsDirectory]; | |
[file changeDirectory:@"Assets"]; | |
[file makeDirectory]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YKFile *file = [YKFile documentsDirectory]; | |
[file makeDirectory:@"Assets"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YKFile *file = [YKFile documentsDirectory]; | |
[file cd: @"abc/def/*/*"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[UIImage imageWithContentsOfFile:file.fullPath]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YKFile *file = [YKFile documentsDirectory]; | |
[file changeDirectory:@"Assets"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YKFile *file = [YKFile documentsDirectory]; | |
[file changeDirectory:@"Assets/dir1/file1.text"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)eachFile:(void (^)(YKFile *file, NSUInteger idx))pFunction; | |
- (void)sortFiles:(NSComparisonResult (^)(YKFile *file1, YKFile *file2))pFunction; | |
- (void)removeFilesFromList:(BOOL (^)(YKFile *file))pFunction; | |
- (YKFileArray *)cutFilesFromList:(BOOL (^)(YKFile *file))pFunction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (instancetype)homeDirectory; | |
+ (instancetype)mainBundleDirectory; | |
+ (instancetype)cachesDirectory; | |
+ (instancetype)documentsDirectory; | |
+ (instancetype)temporaryDirectory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - Aliases | |
- (void)cd:(NSString *)path; | |
- (void)cd; | |
- (BOOL)mkdir:(NSString *)dirName; | |
- (BOOL)mkdirs:(NSString *)dirName; | |
- (BOOL)mkdir; | |
- (BOOL)mkdirs; | |
- (BOOL)rm:(NSString *)name; | |
- (BOOL)rm; | |
- (BOOL)cp:(YKFile *)destination; | |
- (BOOL)mv:(YKFile *)destination; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - 'cd' Method | |
- (void)changeDirectory:(NSString *)path { | |
NSArray *components = path.pathComponents; | |
for (int i = 0; i < [components count]; i++) { | |
NSString *component = components[i]; | |
if (i == 0 && [component isEqualToString:@"~"]) { // cd ~ | |
_fullPath = NSHomeDirectory(); | |
} else if ([component isEqualToString:@".."]) { // cd .. | |
_fullPath = self.parentFile.fullPath; | |
} else if ([component isEqualToString:@"."]) { // cd . | |
} else if ([component isEqualToString:@"*"]) { // cd to first found file or directory | |
YKFileArray *list = [self listFiles]; | |
for (YKFile *file in list) { | |
if ([file.name isEqual:@".DS_Store"]) continue; | |
if ([file.name isEqual:@"Thumbs.db"]) continue; | |
_fullPath = file.fullPath; | |
break; | |
} | |
} else { // cd component | |
_fullPath = [_fullPath stringByAppendingPathComponent:component]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment