renaming directories and moving files into them (NSFileManager)
renaming directories and moving files into them (NSFileManager)
- Subject: renaming directories and moving files into them (NSFileManager)
- From: Scott Anguish <email@hidden>
- Date: Fri, 15 Apr 2011 01:47:56 -0400
OK, before anyone asks... I’m working on a tool for my own use, and so I don’t want to bug people at work about it.
Thus, I bug you. :-)
I’m perplexed by this one.
I’m trying something stupidly simple, and I’m getting really odd results.
I have an app that sorts a bunch of files and sticks them in a newly made directories. When it finds a file that identifies WhereFroms (via spotlight, from a downloaded file) I want it to rename that directory and then copy the rest of the related files into that directory
All this seems really straight forward. I’m using NSFileManager moveItemAtPath:toPath:error:
Code, whittled down to the important stuff..
shootPath is the original path that things are getting copied to. (for example /tmp/boo/Friday) and files are copied into that.
if ([[eachPath pathExtension] isEqualToString:@"mp4"]) {
MDItemRef fileMetadata=MDItemCreate(NULL,(CFStringRef)eachPath);
NSDictionary *metadataDictionary= (NSDictionary*)MDItemCopyAttributes (fileMetadata,(CFArrayRef)[NSArray arrayWithObject:(id)kMDItemWhereFroms]);
NSString *whereFrom=[[metadataDictionary objectForKey:(id)kMDItemWhereFroms] lastObject];
NSURL *whereFromURL=[NSURL URLWithString:whereFrom];
NSString *rawDomain=[whereFromURL host];
NSRange foundRange=[rawDomain rangeOfString:@“apple" options:(NSCaseInsensitiveSearch)];
NSLog(@"foundRange - %d,%d",foundRange.location,foundRange.length);
// all the above works fine
if (foundRange.location > 0) { // should be comparing to NSNotFound, but that failed miserably.
newShootPath=[shootPath stringByAppendingString:@“-APPL”];
// make sure I’ve not already done this
if (![self directoryExists:newShootPath]) {
success=[fileManager moveItemAtPath:shootPath toPath:newShootPath error:&theError];
NSLog(@"should be moving - %d",success);
//success is true!
// make the newShootPath, the shootPath for other files
[shootPath autorelease];
shootPath=[newShootPath retain];
// this just updates a table for progress
if (!success)
tempTableitem.error=theError;
[self addObjectToTableContents:tempTableitem];
[tempTableitem release];
theError=nil;
}
}
}
It always creates a new directory wit the new name, in the existing shootPath directory (for example /tmp/boo/Friday) with Friday-APPL instead. and then copies the newly found files into that. I’m boggled.
what am I missing?
Any ideas_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden