Created
May 17, 2016 22:14
-
-
Save simonbromberg/ba12308bc0b80839105a796a00bd858f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)replaceFileNamesOfImagesWithUUIDsAtPath:(NSString *)path { | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSURL *directoryURL = [NSURL fileURLWithPath:path]; | |
NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey]; | |
NSDirectoryEnumerator *enumerator = [fileManager | |
enumeratorAtURL:directoryURL | |
includingPropertiesForKeys:keys | |
options:0 | |
errorHandler:^(NSURL *url, NSError *error) { | |
// Handle the error. | |
// Return YES if the enumeration should continue after the error. | |
return YES; | |
}]; | |
for (NSURL *url in enumerator) { | |
NSError *error; | |
NSNumber *isDirectory = nil; | |
if (! [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) { | |
// handle error | |
} | |
else if (! [isDirectory boolValue]) { | |
if ([url.pathExtension isEqualToString:@"png"]) { | |
NSLog(@"%@", url.path); | |
NSString *uuid = [[NSUUID UUID] UUIDString]; | |
[[NSFileManager defaultManager] moveItemAtPath:url.path toPath:[path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", uuid]] error:nil]; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment