Binary Copy

Hi All,

I am very new to XOJO. I am aware (through experience) that using XOJO’s copyto feature freezes the UI and the Macintosh it runs on. Someone has suggested using a binary copy to copy folder a to folder b.

Im not going to lie the concept is alien to me. Is anyone able to point me towards a real basic (Dummies) guide on how to build / implement or willing to help me out in this thread please?


Ive found this……

[code] // This method employs binarystreams to copy FromFile to ToFile

dim FromStream, ToStream as BinaryStream

// Open the streams up
FromStream = FromFile.OpenAsBinaryFile(false)
ToStream = ToFile.CreateBinaryFile("")

// Copy the data from one stream to another
while not FromStream.EOF

// Close the streams

A possibly better approach is to use the ditto command (or similar commands) in a shell. Let the shell copy files quickly, reliably, and asynchronously — it’s much better at it than Xojo.

Hey Walter,

I totally agree, but ice been using that method for so long, i was hoping to be able to build it in XOJO that rely on terminal.

I’ve made the following push button:

[code] Dim main As FolderItem
Dim otherdir As FolderItem
Dim f As folderitem

f = SpecialFolder.Desktop.Child( “a” )
otherdir = SpecialFolder.Desktop.Child( “b” )


But it crashes on :

while not FromStream.EOF

It’s not just a Xojo problem. If you copy or delete large files on the main thread in Cocoa you run into the same freezing problem. It was something I experienced with the first two iterations of MacDust.

Is FolderItem.CopyFileTo usable on a thread?

No idea sorry Tim, I’m very new to these concepts. I used to push a cp command through to terminal via applescript connection in XOJO, but its becoming a hassle to keep updating code etc with Mac OSX updates etc. I just wanted to make an app that did the job instead of having various applescript terminal commands, and having to have timers to control when they fire

There is a Monkeybread plugin, but i think its overkill to pay 50.00 GBP for it.

MBS Plugins have a couple of copy functions which work in background…

Hey Christian, as above, i don’t see the value in spending lots of money for a homemade app that will be used for one purpose. Thanks though

Just use a thread for this.

He Christoph, as per initial post, i am unsure how to do this, i don’t expect someone to code it for me, but if able to point me towards a simple, dummys one so i can get to understand it would be great.

All i want to do is copy folder a to folder b

it depends on what you want.
If you have MBS, it’s not costing extra.

If you are happy with calling shell command, you are also happy.
And if you just make copies with binary stream, you may be happy. Until you also want to copy all the permissions and metadata…

@Christian Schmitz - do you have any links to Monkeybread Plugins 12.4? I have been to the site and they no longer are available?

Well it seems that threading a CopyFileTo doesn’t actually free up the interface.
Tested copying a 200mb folder.

Did I do something wrong?
CopyThreaded.xojo_binary_project - 37kb

No. CopyFileTo isn’T thread friendly.

@Jay: Email me and I can send you back a link.

Good to know.
Thanks, Christian.

@Christian Schmitz - Done

When you can’t use a thread, consider a helper app.
Effectively, a very small app that does nothing but copy A to B, then dies.

Your main app launches the helper app and tells it which files to copy.

Thanks Jeff,

I am playing with the Monkey bread plugin now, and now I’m having the next issue. I’ve tried going through their site, but its not as easy as the XOJO wiki :frowning:

I want to copy folders in order. The code here prints out via a method the files being copied from A > B. What i am trying to do is print out A > B, then when A > B finishes in then starts C > D. I cannot see a way to do it :frowning:

[code] dim source, dest as FolderItem

source=SpecialFolder.Desktop.Child(“A”) // Copying From
dest=SpecialFolder.Desktop.Child(“B”) // Copying To

m=new MyFileOperation

m.CopyObject(source, dest, “”, m.kFSFileOperationDefaultOptions,1.0)

dim source2, dest2 as FolderItem

source2=SpecialFolder.Desktop.Child(“C”) // Copying From
dest2=SpecialFolder.Desktop.Child(“D”) // Copying To

m=new MyFileOperation

m.CopyObject(source2, dest2, “”, m.kFSFileOperationDefaultOptions,1.0)

// Takes Source and destination and pushes data through
// 1.0 is the speed that is reported back to the system.[/code]