NSTask and copying lots of small files
NSTask and copying lots of small files
- Subject: NSTask and copying lots of small files
- From: Jonathan Fewtrell <email@hidden>
- Date: Sat, 28 Jan 2006 19:02:22 +0000
My app copies a directory from CD to the hard drive. The directory
contains a few hundred small files (say 10k each).
If I use NSFileManager's copyPath method, the process is very slow.
Several minutes to copy a directory that in total is only about 3MB.
It is also rather nerve-wracking in that it makes the CD drive
chatter throughout the process, presumably because it is seeking and
copying one small file at a time. If I copy the directory in the
Finder, the same thing happens.
However, if I use ditto from the Terminal, it all happens very
smoothly in about 20 seconds with no chattering. So I tried using
ditto via an NSTask:
- (BOOL)dittoFromPath:(NSString *)source toPath:(NSString *)target
{
NSTask *copyTask;
NSArray *arguments;
int outcome;
arguments = [NSArray arrayWithObjects:source, target, nil];
copyTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/ditto"
arguments:arguments];
[copyTask waitUntilExit];
outcome = [copyTask terminationStatus];
return outcome == 0? YES : NO;
}
But this gives the same slowness and chattering as using NSFileManager.
If ditto is a separate process why shouldn't it run as efficiently
when invoked from NSTask as it does when invoked from Terminal? Any
other way I can get a smooth copying process?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden