3

The "source" below is a mounted disc image (dmg), named "New." I'm trying to rename it with a textField string and action. When I complete the action the rename fails and I am unable to eject it. The code works with standard files and folders.

Also - if I do a "Get Info" of the mounted disc image and rename it there, everything works fine.

Bottom line is I want to rename a mounted disc image using a textField string. Can someone explain?

NSString *source = [@"~/Desktop/New" stringByExpandingTildeInPath];
NSString *newFile = [input stringValue];
NSString *newPath = [[source stringByDeletingLastPathComponent] stringByAppendingPathComponent:newFile];
[[NSFileManager defaultManager] moveItemAtPath:source toPath:newPath error:NULL];
NSLog(@"File renamed to %@", newFile);
Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
Paul
  • 101
  • 1
  • 6
  • Are you trying to rename the disk image file or the volume inside the image? – Chuck Jul 13 '11 at 23:04
  • It's shown on your desktop, but might not be mounted in `~/Desktop/`. Disk images, network shares and external drives are typically mounted in `/Volumes/`. – Cyrille Jun 12 '15 at 09:50

1 Answers1

1

You'll need to use the disk arbitration framework.

MiB
  • 575
  • 2
  • 10
  • 26
Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135