But seriously... there's more going on in your code than in mine, so the problem must lie in whatever is different (or be somehow caused by the data rather than the code). Like you say, what you're doing *seems* pretty straightforward and what you're seeing *seems* impossible (my favorite kind of bug).
Lots of questions, mainly along the lines of ruling out as much as possible: * Did you see my previous question? It looked like your logic would result in directories xxx-APPL, xxx-APPL-APPL, xxx-APPL-APPL-APPL, etc. -- or was I mistaken? If there is code elsewhere that is resetting shootPath to not have the APPL suffix, could you be inadvertently recreating the old directory? What if you put an NSLog after every line of code that does a mkdir, to make sure directories only get created once? Are you sure it's the mp4 files you copy *after* renaming the directory that get put in the new directory? * What if you put a breakpoint on the call to moveItemAtPath:toPath:error: and step over it? Do you see in the Finder that there is one directory before the call and two directories afterward? If so, there's your smoking gun that there's a bug in the method. If you see only one directory (with the new name), that would suggest that moveItemAtPath:toPath:error: is doing its job as expected and something else is recreating the old directory. * What if you don't use NSFileManager to rename the directory, but rename([shootPath UTF8String], [newShootPath UTF8String])? * To use the simplest dataset possible: what if you hardcode it to copy two specific mp4 files, where the second triggers the directory rename? Does this reproduce the bug? * What if you comment out the code that copies the mp4 files -- do you still get two directories (which are now empty instead of containing copies of the files)? * Are you using copyItemAtPath:toPath:error: like I did, or something else to copy the files? --Andy On Apr 17, 2011, at 10:41 PM, Scott Anguish wrote: > not sure what to say, my code wasn’t doing that. > > I ended up churning through all the files once, finding the .mp4s, getting > the whereas information and then making the directory I needed first. > > I just didn’t have more time to spend trying to figure it out. > > Now I feel like I need to though... :-/ > > that it was ‘making’ a new directory with -APPL at the end was the oddest > part. rather than moving it. > > On Apr 17, 2011, at 1:59 AM, Andy Lee wrote: > >> I tried to reproduce your problem by creating directories ~/wtf/FromHere and >> ~/wtf/ToHere, with three files in FromHere named 1, 2, and 3. I switch over >> to using "ToHere-NEW" when it detects a file whose name is >= "2". >> >> My test code renamed the directory and switched over to it just fine: >> >> - (void)test >> { >> NSFileManager *fileManager = [NSFileManager defaultManager]; >> NSString *fromDir = [@"~/wtf/FromHere" stringByStandardizingPath]; >> NSString *originalToDir = [@"~/wtf/ToHere" stringByStandardizingPath]; >> NSString *toDir = originalToDir; >> NSError *error = nil; >> NSArray *filesToCopy = [[fileManager contentsOfDirectoryAtPath:fromDir >> error:&error] >> >> sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; >> >> for (NSString *fileName in filesToCopy) >> { >> // Rename the destination directory if necessary. >> if ([fileName intValue] >= 2) >> { >> NSLog(@"File name is %@; will rename directory if necessary.", >> fileName); >> >> NSString *newToDir = [originalToDir >> stringByAppendingString:@"-NEW"]; >> >> if (![fileManager fileExistsAtPath:newToDir]) >> { >> if ([fileManager moveItemAtPath:toDir toPath:newToDir >> error:&error]) >> { >> NSLog(@"...SUCCESS: Renamed %@ to %@.", toDir, newToDir); >> } >> else >> { >> NSLog(@"...ERROR: Failed to rename %@ to %@ -- %@.", >> toDir, newToDir, error); >> abort(); >> } >> >> toDir = newToDir; >> } >> else >> { >> NSLog(@"...%@ already exists; no need to rename.", newToDir); >> } >> } >> >> // Move the file to the directory at shootPath. >> NSString *oldFilePath = [fromDir >> stringByAppendingPathComponent:fileName]; >> NSString *newFilePath = [toDir >> stringByAppendingPathComponent:fileName]; >> >> if ([fileManager copyItemAtPath:oldFilePath toPath:newFilePath >> error:&error]) >> { >> NSLog(@"Copied file %@ to %@.", oldFilePath, newFilePath); >> } >> else >> { >> NSLog(@"...ERROR: Failed to copy %@ to %@ -- %@.", oldFilePath, >> newFilePath, error); >> abort(); >> } >> } >> } >> >> 2011-04-17 01:46:41.013 Scratcho[2630:a0f] Copied file >> /Users/alee/wtf/FromHere/1 to /Users/alee/wtf/ToHere/1. >> 2011-04-17 01:46:41.014 Scratcho[2630:a0f] File name is 2; will rename >> directory if necessary. >> 2011-04-17 01:46:41.069 Scratcho[2630:a0f] ...SUCCESS: Renamed >> /Users/alee/wtf/ToHere to /Users/alee/wtf/ToHere-NEW. >> 2011-04-17 01:46:44.712 Scratcho[2630:a0f] Copied file >> /Users/alee/wtf/FromHere/2 to /Users/alee/wtf/ToHere-NEW/2. >> 2011-04-17 01:46:44.712 Scratcho[2630:a0f] File name is 3; will rename >> directory if necessary. >> 2011-04-17 01:46:44.713 Scratcho[2630:a0f] .../Users/alee/wtf/ToHere-NEW >> already exists; no need to rename. >> 2011-04-17 01:46:46.934 Scratcho[2630:a0f] Copied file >> /Users/alee/wtf/FromHere/3 to /Users/alee/wtf/ToHere-NEW/3. >> >> --Andy >> > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com