[Solved] CopyFile() and CopyDirectory()

Mac OSX specific forum
XaGau
New User
New User
Posts: 4
Joined: Tue Aug 28, 2012 5:54 pm

[Solved] CopyFile() and CopyDirectory()

Post 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
Last edited by XaGau on Mon Apr 28, 2014 5:11 pm, edited 1 time in total.
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: CopyFile() and CopyDirectory()

Post by Wolfram »

Did you compare the package contents of both?
macOS Catalina 10.15.7
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: CopyFile() and CopyDirectory()

Post 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", "")
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
XaGau
New User
New User
Posts: 4
Joined: Tue Aug 28, 2012 5:54 pm

Re: CopyFile() and CopyDirectory()

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: CopyFile() and CopyDirectory()

Post by wilbert »

You could try using CocoaMessage.
The NSFileManager class has a method named copyItemAtPath:toPath:error:
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: CopyFile() and CopyDirectory()

Post 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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
XaGau
New User
New User
Posts: 4
Joined: Tue Aug 28, 2012 5:54 pm

Re: CopyFile() and CopyDirectory()

Post by XaGau »

Hello all,

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

Cordially
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

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

Post 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.
Post Reply