OC 언어 day08-15 파일 관리 NSFileManager
pragmamark 개념
/**
:
/
NSFileManager( )
1. / (fileExistsAtPath: / )
2. , (fileExistsAtPath:isDirectory)
3. (attributesOfItemAtPath:error)
4. (contentsOfDirectoryAtPath: error)
5. (subpathsAtPath: ) (subpathsOfDirectoryAtPath)
<1>
6. (copyItemAtPath:toPath:error)
7. ( ) (moveItemAtPath:toPath:error)
8. (removeItemAtPath:error)
<2>
10. (createDirectoryAtPath:withIntermediateDirectories:attributes)
11. (createFileAtPath:contents:attributes)
*/
pragmamark 코드
#import
#pragma mark
#pragma mark main
int main(int argc, const char * argv[])
{
#pragma mark 1. NSFileManager( )
/**
:
/
*/
NSFileManager *fm1 = [NSFileManager defaultManager];
NSFileManager *fm2 = [NSFileManager defaultManager];
NSLog(@"%p %p",fm1,fm2);
#pragma mark bool 1 、
NSFileManager *manager = [NSFileManager defaultManager];
#warning 1. / (fileExistsAtPath)
// BOOL flag = [manager fileExistsAtPath:@"/Users/liyuhong165/Desktop/ "]; //
BOOL flag = [manager fileExistsAtPath:@"/Users/liyuhong165/Desktop/ /abc.txt"]; //
NSLog(@"flag = %i",flag);
#warning 2. , (fileExistsAtPath:isDirectory)
/**
:
isDirectory : ,
, YES,
NO
*/
BOOL dir = NO;
flag = [manager fileExistsAtPath:@"/Users/liyuhong165/Desktop/ /abc.txt" isDirectory:&dir];
NSLog(@"2. flag = %i dir = %i",flag,dir);
#warning 3. (attributesOfItemAtPath:error)
NSDictionary *info = [manager attributesOfItemAtPath:@"/Users/liyuhong165/Desktop/ /abc.txt" error:nil];
NSLog(@"3.info = %@",info);
#warning 4. (contentsOfDirectoryAtPath: error)
/**
: contentsOfDirectoryAtPath
,
*/
NSArray *res = [manager contentsOfDirectoryAtPath:@"/Users/liyuhong165/Desktop/ " error:nil];
NSLog(@"4.res %@",res);
#warning 5. (subpathsAtPath: ) (subpathsOfDirectoryAtPath)
NSArray *res1 = [manager subpathsAtPath:@"/Users/liyuhong165/Desktop/ "];
NSArray *res2 = [manager subpathsOfDirectoryAtPath:@"/Users/liyuhong165/Desktop/ " error:nil];
NSLog(@"5.res1 %@",res1);
NSLog(@"5.res2 %@",res2);
#pragma mark 2.
#warning 6. (copyItemAtPath:toPath:error)
// [manager copyItemAtURL:@" " toURL:@" " error:1];
#warning 7. ( ) (moveItemAtPath:toPath:error)
#warning 8. (removeItemAtPath:error)
#pragma mark 3.
#warning 10. (createDirectoryAtPath:withIntermediateDirectories:attributes)
/**
createDirectoryAtPath :
withIntermediateDirectories : ,
attributes: (no)
error: a
// ⚠️: ,
*/
flag = [manager createDirectoryAtPath:@"/Users/liyuhong165/Desktop/age/lyh" withIntermediateDirectories:NO attributes:nil error:nil];
NSLog(@"10.flag = %hhd",flag);
#warning 11. (createFileAtPath:contents:attributes)
/**
createFileAtPath :
contents :
// ⚠️: ,
*/
// NSData :
NSString *str = @" , ";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
[manager createFileAtPath:@"/Users/liyuhong165/Desktop/lyh/hehe.txt" contents:data attributes:nil];
/*
// :
// : attributesOfItemAtPath ,
// , ,
#warning 3.
#warning 4.
#warning 5.
*/
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.