In Cocoa, is there any way to copy all the files in a directory without copying the directory's subdirectories along with them?
+1
A:
One way would be to copy items in the directory conditionally based on the results of NSFileManager
s -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) // ...
}
Georg Fritzsche
2010-05-29 04:58:00
That works for me.
Nano8Blazex
2010-05-29 05:03:49