-
-
Save fra3il/08463c50ffbd22fe1eb6 to your computer and use it in GitHub Desktop.
[WP/159] mainBundle, Documents
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
// mainBundle 의 파일 목록 가져오기 | |
- (void)mainBundleList { | |
NSString *path = [[NSBundle mainBundle] bundlePath]; | |
NSArray *list = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; | |
NSLog(@"%@", list); | |
// .jpg 로 끝나는 파일만 보여준다 | |
NSArray *onlyJPG = [list filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.jpg'"]]; | |
NSLog(@"%@", onlyJPG); | |
} | |
// Documents 의 파일 목록 가져오기 | |
- (void)documentsList { | |
NSString *path = [NSString stringWithFormat:@"%@/Documents/", NSHomeDirectory()]; | |
NSArray *list = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; | |
NSLog(@"%@", list); | |
} | |
// mainBundle 의 파일을 Documents 로 복사하기 | |
- (void)copyFile { | |
// documents 폴더로 복사할 파일 | |
NSArray *fileList = [NSArray arrayWithObjects:@"IMG_0657.MOV", @"maltese.jpg", nil]; | |
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
for (NSInteger i = 0; i < [fileList count]; i++) { | |
NSString *fileName = [fileList objectAtIndex:i]; | |
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName]; | |
NSString *toPath = [documentsDirectory stringByAppendingPathComponent:fileName]; | |
// documents 폴더에 파일이 존재하지 않으면 복사 | |
if (![fileManager fileExistsAtPath:toPath]) { | |
if ([fileManager copyItemAtPath:filePath toPath:toPath error:nil]) { | |
NSLog(@"1"); | |
} else { | |
NSLog(@"0"); | |
} | |
} | |
} | |
} | |
// 특정 디렉토리 아래의 서브 디렉토리를 확인하는 방법 | |
- (NSString *)findSubDirectory { | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"image"];; | |
NSArray *list = [fileManager subpathsOfDirectoryAtPath:path error:nil]; | |
for (NSString *string in list) { | |
BOOL isDir = NO; | |
[fileManager fileExistsAtPath:[path stringByAppendingPathComponent:string] isDirectory:&isDir]; | |
if (isDir) { | |
NSLog(@"%@", string); | |
} | |
} | |
return nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment