OC 언어 day08-15 파일 관리 NSFileManager

4404 단어
pragma mark 파일 관리 NSFile Manager
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;
}

좋은 웹페이지 즐겨찾기