Wednesday, August 26, 2020


Tags

Building a better Mac app with Xojo

Checking to see if two files are on the same volume.

Wednesday, August 26, 2020 - Sam Rowlands

Xojo used to provied an option (folderitem.MacVRefNum) for checking this, but not in recent version, and there's zero mention of this with API 2.0. Thankfully I was able to write out the declares to replace it.

The following code uses the Ohanaware App Kit, but you should be able to translate it to your macOS library of choice.

// --- Now to determine if two files are on the same volume. Dim sourceURL as integer = app.dataFolder.NSURL Dim destURL as integer = newDestination.NSURL Dim nsError as integer Dim sourceVolume as integer if NSURLGetResourceValue( sourceURL, sourceVolume, "NSURLVolumeIdentifierKey", nsError ) = false then MsgBoxError "Cannot check the current source file's volume", NSErrorLocalizedDescription( nsError ), currentMethodName return end if Dim destinationVolume as integer if NSURLGetResourceValue( destURL, destinationVolume, "NSURLVolumeIdentifierKey", nsError ) = false then MsgBoxError "Cannot check the destinations's volume", NSErrorLocalizedDescription( nsError ), currentMethodName return end if if NSObjectisEqual( sourceVolume, destinationVolume ) then // --- Yes, they're on the same volume, we can move. else // --- Not they're not on the same volume. end if