Platforms to show: All Mac Windows Linux Cross-Platform

ExchangeFilesMBS(first as folderitem, second as folderitem) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
global method Files MBS Util Plugin 10.4 ✅ Yes ✅ Yes ❌ No ✅ Yes All
Exchanges two files.
Example
dim f1 as FolderItem = SpecialFolder.Desktop.Child("some picture.jpg")
dim f2 as FolderItem = SpecialFolder.Desktop.Child("another picture.jpg")

dim e as Integer = ExchangeFilesMBS(f1,f2)

MsgBox str(e) // show error code (0=no error)

On Mac swaps the contents of two files:

The ExchangeFilesMBS function allows programs to implement a "safe save" operation by creating and writing a complete new file and swapping the contents. An folderitem, alias, FSSpec, or FSRef that refers to the old file will now access the new data. The corresponding information in in-memory data structures are also exchanged.

Either or both files may have open access paths. After the exchange, the access path will refer to the opposite file's data (that is, to the same data it originally referred, which is now part of the other file).

On Windows files are renamed so they exchange their paths.

PS: Xojo does not notice the change, so the folderitems you pass should no longer be used. To access the file, please make new folderitem with parent.truechild(filename).

Blog Entries

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...