Modify a file URL by removing or appending a path

suggest change

URLByDeletingPathExtension

If the receiver is a root path, the result is a copy of the original URL. If the URL has multiple path extensions, only the last one is removed.

URLByAppendingPathExtension:

Returns a new URL made by appending a path extension to the original URL.

Example:

NSUInteger count = 0;
     NSString *filePath = nil;
     do {
         NSString *extension = CFBridgingRelease(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)AVFileTypeQuickTimeMovie, kUTTagClassFilenameExtension));
         NSString *fileNameNoExtension = [[asset.defaultRepresentation.url URLByDeletingPathExtension] lastPathComponent];
         NSString *fileName = [NSString stringWithFormat:@"%@-%@-%lu", fileNameNoExtension, AVAssetExportPresetLowQuality, (unsigned long)count];
         filePath = NSTemporaryDirectory();
         filePath = [filePath stringByAppendingPathComponent:fileName];//Appending is used
         filePath = [filePath stringByAppendingPathExtension:extension];
         count++;

     } while ([[NSFileManager defaultManager] fileExistsAtPath:filePath]);

     NSURL *outputURL = [NSURL fileURLWithPath:filePath];

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents