Skip to content

Instantly share code, notes, and snippets.

@simonbromberg
Created May 17, 2016 22:14
Show Gist options
  • Save simonbromberg/ba12308bc0b80839105a796a00bd858f to your computer and use it in GitHub Desktop.
Save simonbromberg/ba12308bc0b80839105a796a00bd858f to your computer and use it in GitHub Desktop.
- (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