//도큐먼트 폴더 주소
NSString *documentsDir = [NSString stringWithString:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]];
//라이브러리 폴더 주소
NSString *LibraryDir = [NSString stringWithString:[NSHomeDirectory() stringByAppendingPathComponent:@"Library"]];
//라이브러리->캐쉬폴더 폴더주소
NSString *Library_CachesDir = [NSString stringWithString:[LibraryDir stringByAppendingPathComponent:@"Caches"]];
NSFileManager *fm = [NSFileManager defaultManager];
//도큐먼트 폴더안에 있는 파일 리스트 가져온다.
NSArray *list = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDir error:nil];
//파일 리스트 갯수를 가져와서..
int fileCount = [list count];
//갯수가 0이 아니면 아래 실행..(갯수가 0이면 빈 폴더임)
if (fileCount!=0)
{
//도큐먼트안에 파일들을 라이브러리->캐쉬 폴더로 이동시킨다.
for (NSString *path in [fm contentsOfDirectoryAtPath:documentsDir error:nil])
{
[fm moveItemAtPath:[documentsDir stringByAppendingPathComponent:path] toPath:[Library_CachesDir stringByAppendingPathComponent:path] error:nil];
}
//도큐멘트 안에 파일을 지운다.
for (NSString *path in [fm contentsOfDirectoryAtPath:documentsDir error:nil])
{
[fm removeItemAtPath:[documentsDir stringByAppendingPathComponent:path] error:nil];
}
}
참고 주소 : http://jaesung2124.tistory.com/31