Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacClassic Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacClassic/MacFileUtil sync
This example is the version from Thu, 31th Jul 2019.
Project "MacFileUtil sync.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
dim f as FolderItem
f=SpecialFolder.Desktop.Child("test folder")
if f.Exists then
StaticText2.text="This folder exists already!"
return
end if
f.CreateAsFolder
if f.Exists then
StaticText2.text="OK"
testfolder=f
else
StaticText2.text="Failed to create folder"
end if
CheckButtons
End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
dim f as FolderItem
f=SpecialFolder.Desktop.Child("test file")
if f.Exists then
StaticText3.text="This file exists already!"
return
end if
dim b as TextOutputStream
b=f.CreateTextFile
if b<>nil then
b.WriteLine "Hello World"
b.Close
StaticText3.text="OK"
testfile=f
else
StaticText3.text="Failed to create file!"
end if
CheckButtons
End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
dim result as FolderItem
const kFSFileOperationDefaultOptions=0 // Use the default options - no overwrite, fail if any source item cannot be read, cross volume moves OK.
const kFSFileOperationOverwrite=1 // Replace an item in the destDir that has the same name as an item being moved/copied there.
const kFSFileOperationSkipSourcePermissionErrors=2 // Skip items that cannot be read and continue copying/moving instead of failing the operation.
const kFSFileOperationDoNotMoveAcrossVolumes=4 // Do not perform a copy/delete to move an item across volume boundries - fail the operation instead.
const kFSFileOperationSkipPreflight=8 // Skip the preflight for a directory move/copy. This will limit the status information that can be returned since the totals will not be calculated.
dim e as integer=testfile.MacCopyObjectMBS(testfolder, "new filename", result, kFSFileOperationDefaultOptions)
if e=0 then
StaticText4.text="OK: "+result.NativePath
else
StaticText4.text="Error: "+str(e)
end if
CheckButtons
End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action()
dim result as FolderItem
const kFSFileOperationDefaultOptions=0 // Use the default options - no overwrite, fail if any source item cannot be read, cross volume moves OK.
const kFSFileOperationOverwrite=1 // Replace an item in the destDir that has the same name as an item being moved/copied there.
const kFSFileOperationSkipSourcePermissionErrors=2 // Skip items that cannot be read and continue copying/moving instead of failing the operation.
const kFSFileOperationDoNotMoveAcrossVolumes=4 // Do not perform a copy/delete to move an item across volume boundries - fail the operation instead.
const kFSFileOperationSkipPreflight=8 // Skip the preflight for a directory move/copy. This will limit the status information that can be returned since the totals will not be calculated.
dim e as integer=testfile.MacMoveObjectMBS(testfolder, "", result, kFSFileOperationDefaultOptions)
if e=0 then
StaticText5.text="OK: "+result.NativePath
else
StaticText5.text="Error: "+str(e)
end if
CheckButtons
End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action()
dim result as FolderItem
const kFSFileOperationDefaultOptions=0 // Use the default options - no overwrite, fail if any source item cannot be read, cross volume moves OK.
const kFSFileOperationOverwrite=1 // Replace an item in the destDir that has the same name as an item being moved/copied there.
const kFSFileOperationSkipSourcePermissionErrors=2 // Skip items that cannot be read and continue copying/moving instead of failing the operation.
const kFSFileOperationDoNotMoveAcrossVolumes=4 // Do not perform a copy/delete to move an item across volume boundries - fail the operation instead.
const kFSFileOperationSkipPreflight=8 // Skip the preflight for a directory move/copy. This will limit the status information that can be returned since the totals will not be calculated.
dim e as integer=testfolder.MacMoveObjectToTrashMBS(result, kFSFileOperationDefaultOptions)
if e=0 then
StaticText6.text="OK: "+result.NativePath
else
StaticText6.text="Error: "+str(e)
end if
testfolder=nil
CheckButtons
End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Sub CheckButtons()
if testfolder<>nil and testfile<>Nil then
PushButton3.Enabled=true
PushButton4.Enabled=true
PushButton5.Enabled=true
else
PushButton3.Enabled=false
PushButton4.Enabled=false
PushButton5.Enabled=false
end if
End Sub
Property testfile As FolderItem
Property testfolder As FolderItem
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS MacClassic Plugin.