Page 1 of 1

[Solved] CopyFile() and CopyDirectory()

Posted: Sat Apr 26, 2014 10:28 am
by XaGau
Hello all,

Know you why, when I copy an application with PB copyfile or copydirectory, copied application does not start?
While when I make it manually, it starts normally?

Best regards

Re: CopyFile() and CopyDirectory()

Posted: Sat Apr 26, 2014 11:00 am
by Wolfram
Did you compare the package contents of both?

Re: CopyFile() and CopyDirectory()

Posted: Sat Apr 26, 2014 12:36 pm
by TI-994A
XaGau wrote:...when I copy an application with PB copyfile or copydirectory, copied application does not start?
Hi XaGau. For OSX programs, the app file is actually a folder, so you'd need to copy the single app file with PureBasic's CopyDirectory() function. For example:

Code: Select all

CopyDirectory("/Applications/Calculator.app", "/Users/[username]/Calculator.app", "")

Re: CopyFile() and CopyDirectory()

Posted: Sat Apr 26, 2014 1:58 pm
by XaGau
HI,
Thank you for replys.

I used CopyDirectory, and all the folders and files of the .app are copied, but the executable in \Contents\MacOS\ becomes a document

Best Regards

Re: CopyFile() and CopyDirectory()

Posted: Sat Apr 26, 2014 3:24 pm
by wilbert
You could try using CocoaMessage.
The NSFileManager class has a method named copyItemAtPath:toPath:error:

Re: CopyFile() and CopyDirectory()

Posted: Sat Apr 26, 2014 4:36 pm
by TI-994A
XaGau wrote:I used CopyDirectory, and all the folders and files of the .app are copied, but the executable in \Contents\MacOS\ becomes a document
Hello again XaGau. After reading your last post, I took another look at it, and the results are quite strange. PureBasic's CopyDirectory() function does not seem to work stably with application files (.app). The copied applications work some of the time, and some of the time they are copied with zero bytes. I'm not quite sure what's causing this. I'm running PureBasic 5.20 LTS on OSX 10.8.

As a workaround, if you wouldn't mind using the API, you could use wilbert's suggestion:

Code: Select all

CocoaMessage(0, (CocoaMessage(0, 0, "NSFileManager defaultManager")), "copyItemAtPath:$", @"/Applications/Calculator.app", "toPath:$", @"/Users/[username]/Calc.app", "error:", #nil)
or parse it like this for better clarity:

Code: Select all

NSFM = CocoaMessage(0, 0, "NSFileManager defaultManager")
sourceFile.s = "/Applications/Calculator.app"
destinationFile.s = "/Users/[username]/Calc.app"

CocoaMessage(0, NSFM, "copyItemAtPath:$", @sourceFile, "toPath:$", @destinationFile, "error:", #nil)
Here are some references that might be helpful: :)
- The PureBasic Manual - CocoaMessage()
- Mac Developer Library - NSFileManager Class Reference

Re: CopyFile() and CopyDirectory()

Posted: Mon Apr 28, 2014 5:07 pm
by XaGau
Hello all,

Thank you very much for your help, everything works well now.

Cordially

Re: [Solved] CopyFile() and CopyDirectory()

Posted: Tue Dec 17, 2019 5:21 am
by Rinzwind
Old topic, but it seems CopyDirectory removes the executable permission of files when copying... seems wrong to me? That's why an .app won't start anymore after being copied with CopyDirectory.