Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Win/Windows File Copy
Function:
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Windows File Copy
This example is the version from Sun, 17th Mar 2012.
Project "Windows File Copy.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() if not TargetWin32 then MsgBox "This example is for Windows only." quit end if End EventHandler
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Desktop.Child("source.txt") dest=SpecialFolder.Desktop.Child("dest.txt") if dest.Exists then dest.Delete dim t as TextOutputStream t=source.CreateTextFile t.write "Hello World" t.Close MsgBox "Copy "+source.AbsolutePath+" to "+dest.AbsolutePath dim w as new WindowsFileCopyMBS if w.CopyFileSimple(source,dest) then List.AddRow "CopyFile: OK" else List.AddRow "CopyFile: Failed" end if End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Desktop.Child("source.txt") dest=SpecialFolder.Desktop.Child("dest.txt") dim t as TextOutputStream t=source.CreateTextFile t.write "Hello World" t.Close MsgBox "Copy "+source.AbsolutePath+" to "+dest.AbsolutePath dim w as new MyWinCopy if w.CopyFileEx(source,dest,0) then List.AddRow "CopyFileEx: OK" else List.AddRow "CopyFileEx: Failed" end if End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Desktop.Child("source.txt") dest=SpecialFolder.Desktop.Child("dest.txt") dim t as TextOutputStream t=source.CreateTextFile t.write "Hello World" t.Close MsgBox "Copy "+source.AbsolutePath+" to "+dest.AbsolutePath dim w as new MyWinCopy w.Parent=self if w.FileOperationCopy(source,dest,0,"Copying files from REALbasic...") then List.AddRow "FileOperationCopy: OK" if w.OperationsAborted then List.AddRow "Operations was aborted." else List.AddRow "Operations was successful." end if else List.AddRow "FileOperationCopy: Failed" end if End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Windows dest=SpecialFolder.Desktop.Child("Copy of Windows folder") MsgBox "Copy "+source.AbsolutePath+"* to "+dest.AbsolutePath dim w as new MyWinCopy w.Parent=self if w.FileOperationCopy(source.AbsolutePath+"*",dest,0,"Copying files from REALbasic...") then List.AddRow "FileOperationCopy: OK" if w.OperationsAborted then List.AddRow "Operations was aborted." else List.AddRow "Operations was successful." end if else List.AddRow "FileOperationCopy: Failed" end if End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action() dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Windows dest=SpecialFolder.Desktop.Child("Copy of Windows folder") MsgBox "Copy "+source.AbsolutePath+"* to "+dest.AbsolutePath dest.CreateAsFolder dim w as new MyWinCopy dim flags as integer flags=BitwiseOr(flags, w.FileOperationSilent) flags=BitwiseOr(flags, w.FileOperationNoConfirmation) flags=BitwiseOr(flags, w.FileOperationNoConfirmationMkDir) flags=BitwiseOr(flags, w.FileOperationNoErrorUI) w.Parent=self if w.FileOperationCopy(source.AbsolutePath+"*",dest,flags,"Copying files from REALbasic...") then List.AddRow "FileOperationCopy: OK" if w.OperationsAborted then List.AddRow "Operations was aborted." else List.AddRow "Operations was successful." end if else List.AddRow "FileOperationCopy: Failed" end if End EventHandler
End Control
Control PushButton6 Inherits PushButton
ControlInstance PushButton6 Inherits PushButton
EventHandler Sub Action() dim file as FolderItem file=SpecialFolder.Desktop.Child("Copy of Windows folder") MsgBox "Delete "+file.AbsolutePath dim w as new MyWinCopy w.Parent=self if w.FileOperationDelete(file,0) then List.AddRow "FileOperationDelete: OK" if w.OperationsAborted then List.AddRow "Operations was aborted." else List.AddRow "Operations was successful." end if else List.AddRow "FileOperationDelete: Failed" end if End EventHandler
End Control
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
Class MyWinCopy Inherits WindowsFileCopyMBS
EventHandler Function Progress(TotalFileSize as int64, TotalBytesTransferred as int64, StreamSize as int64, StreamBytesTransferred as Int64, StreamNumber as integer, Reason as integer) As integer MainWindow.List.AddRow "Progress..." MainWindow.List.AddRow "TotalFileSize: "+str(TotalFileSize) MainWindow.List.AddRow "TotalBytesTransferred: "+str(TotalBytesTransferred) MainWindow.List.AddRow "StreamSize: "+str(StreamSize) MainWindow.List.AddRow "StreamBytesTransferred: "+str(StreamBytesTransferred) MainWindow.List.AddRow "StreamNumber: "+str(StreamNumber) dim s as string="?" Select case Reason case me.CallbackChunkFinished s="ChunkFinished" case me.CallbackStreamSwitched s="StreamSwitched" end Select MainWindow.List.AddRow "Reason: "+str(Reason)+" = "+s End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo PDF Plugins