본문 바로가기

Development/IOS & Mac

iOS 파일 관련 정리

File이 있는지 체크하기

NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];

if ([filemgr fileExistsAtPath: @"/tmp/myfile.txt" ] == YES)
        NSLog (@"File exists");
else
        NSLog (@"File not found");

File 옮기기

NSFileManager *filemgr;

filemgr = [NSFileManager defaultManager];
if ([filemgr moveItemAtPath: @"/tmp/myfile.txt" toPath: @"/tmp/newfile.txt" error: NULL]  == YES)
        NSLog (@"Move successful");
else
        NSLog (@"Move failed");

File 읽기

NSFileManager *filemgr;
NSData *databuffer;

filemgr = [NSFileManager defaultManager];

databuffer = [filemgr contentsAtPath: @"/tmp/myfile.txt" ];

FIle Directory

FileManager *filemgr;
NSArray *filelist;
int count;
int i;

filemgr =[NSFileManager defaultManager];
filelist = [filemgr contentsOfDirectoryAtPath:@"/" error:NULL];
count = [filelist count];

for(i = 0; i < count; i++)
{
    NSLog(@"%@", [filelist objectAtIndex: i]);
}

경로에 있는 모든 파일 & Directory 탐색


NSFileManager *manger = [NSFileManager defaultManager];

NSDirectoryEnumerator *fileEnumerator = [manger enumeratorAtPath:documentRootPath];

for (NSString *filename in fileEnumerator) {

'Development > IOS & Mac' 카테고리의 다른 글

[IOS Library] SLExpandableTableView  (0) 2014.07.04
[IOS Library] Slide-Menu  (0) 2014.07.04
[IOS Library] SSZipArchive  (0) 2014.06.20
Objective C Handler  (0) 2014.06.18
[iOS] PBJVision  (0) 2014.06.16