Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Returns the path to the application's Documents directory.
- */
- - (NSString *)applicationDocumentsDirectory {
- return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
- }
- #import "StringUtils.h"
- @implementation StringUtils
- + (NSString *)getFullDocumentUrl:(NSString *)fileName
- {
- return [NSString stringWithFormat:@"%@/%@",[self applicationDocumentsDirectory],fileName];
- }
- + (NSString *)applicationDocumentsDirectory
- {
- return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
- }
- @end
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
- NSFileManager *fm = [NSFileManager defaultManager];
- NSArray *filenames = [fm contentsOfDirectoryAtPath:documentsPath error:nil];
- //Match on the filepath leading up to docs directory
- NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^/\S*Documents/"
- options:NSRegularExpressionCaseInsensitive
- error:nil];
- for (NSString *fileName in filenames)
- {
- NSRange fullLength = NSMakeRange(0, [fileName length]);
- //swap out the prepended directory structure with an empty string
- NSString *updatedFileName = [regex stringByReplacingMatchesInString:fileName
- options:0
- range:fullLength
- withTemplate:@""];
- NSString *currentName = [NSString stringWithFormat:@"%@/%@",documentsPath,fileName];
- NSString *updatedName = [NSString stringWithFormat:@"%@/%@",documentsPath,updatedFileName];
- [fm moveItemAtPath:currentName toPath:updatedName error:nil];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement