On Feb 23, 2011, at 6:41 AM, [email protected] wrote:
> I need to write an application that will scan entire drives and compare files
> between the 2 drives. I have already something working but in situations
> where there are a lot of files (hundreds of thousands), the memory
> consumption becomes a problem, leading to slow performance when virtual
> memory is used and, ultimately, sometimes to crashes in malloc.
>
> Of course, I could go with little chunks, comparing, but I need to present a
> window showing which copies of files are more recent on one drive and which
> ones are more recent on the other drive, so I need to keep a list of all the
> files on one drive that are more recent than their counterparts on the other
> drive, and vice versa. This preferably would have to be done in Cocoa, since
> I already have a working solution.
>
> Knowing that I have to support 10.5 but run under 10.6, what would be the
> best way to have a crack at this problem?
>
> All suggestions are welcome!
>
> -Laurent.
You might try using NSDirectoryEnumerator to loop through the files starting at
the top of the drive. I have done something similar such as:
- (IBAction)exterminateFiles:(id)sender
{
[progBar setUsesThreadedAnimation:YES];
[progBar startAnimation:self];
NSFileManager *fileManager = [NSFileManager defaultManager];
int count = 0;
NSString *file;
for (id dir in searchRoots)
{
NSDirectoryEnumerator *dirEnum = [fileManager
enumeratorAtPath:dir];
while (file = [dirEnum nextObject])
{
if ([file hasSuffix:@".DS_Store"])
{
[fileManager removeItemAtPath:[dir
stringByAppendingPathComponent:file] error:NULL];
count++;
}
}
}
[fileCount setStringValue:[NSString stringWithFormat:@"%i files
removed.", count]];
NSBeep();
[progBar stopAnimation:self];
As you suggest, though, this could be slow. Perhaps threading the search or
using Grand Central Dispatch would speed things up. I have not tried this.
Alternatively, if there is a way to read the directory tables for the drive,
perhaps you could speed up the search & process the appropriate files later. If
anyone can point me in the right direction for understanding & accessing drive
information, I would love to be pointed. Also, you might try FSCatalogSearch &
see if that is any faster._______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]