2010-05-29 108 views

回答

4

一種方式是在有條件的基礎上NSFileManager小號-fileExistsAtPath:isDirectory:結果目錄複製項目:

NSFileManager *manager = [NSFileManager defaultManager]; 
NSArray *files = [manager contentsOfDirectoryAtPath:pathFrom error:nil]; 

for (NSString *file in files) { 
    NSString *fileFrom = [pathFrom stringByAppendingPathComponent:file]; 
    BOOL isDir; 

    if (![manager fileExistsAtPath:fileFrom isDirectory:&isDir] || isDir) { 
     continue; 
    } 

    NSString *fileTo = [pathTo stringByAppendingPathComponent:file]; 
    NSError *error = nil; 
    [manager copyItemAtPath:fileFrom toPath:fileTo error:&error]; 
    if (error) // ... 
} 
+0

這對我的作品。 – Vervious 2010-05-29 05:03:49

相關問題