Copy directory
Hi,
i need to copy a directory with some files in it from my bundle to temporary directory, i know that FSCopyObject would do but my code must use 10.3.9 sdk so i need some other way to do it. I was thinking about shell script but how can i run shell script from c++ application ?
i need to copy a directory with some files in it from my bundle to temporary directory, i know that FSCopyObject would do but my code must use 10.3.9 sdk so i need some other way to do it. I was thinking about shell script but how can i run shell script from c++ application ?
NSTask will allow you to run a shell script or System();
Have you taken a look at copyPath:toPath:handler: though? If you are using Cocoa that is.
Have you taken a look at copyPath:toPath:handler: though? If you are using Cocoa that is.
i solved the problem with system() call where as paramater i pass cp -r src_dir dst_dir, and all seems to be working just fine
I would use NSTask or vfork/exec* rather than system; system blocks your thread until it's done, and more importantly, requires you to quote all the arguments correctly for the shell.
OneSadCookie Wrote:I would use NSTask or vfork/exec* rather than system; system blocks your thread until it's done, and more importantly, requires you to quote all the arguments correctly for the shell.
Though that is the right thing to do, it can also make things a fair bit more tricky. It's correct mainly because cp might take a very long time for example if it tries to copy to a network file system that is in the process of being dropped. By not blocking your main thread you don't have to sit there and beach ball.
On the other hand, doing it asynchronously with NSTask or otherwise means that you can't rely on the copy operation being finished on the next line of your code, which may or may not make things more difficult.
Not really sure what my point is... I guess you just have to weigh up the alternatives for your specific task.
Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
If you really want synchronicity, you can sync with NSTask or fork/exec, it's just another line of code. My major point was about quoting shell arguments being a problem with system().
Yeah, quoting things correctly has bitten me in the past. You can't in general just wrap things in quotes unless you are sure that you won't have to escape any pathnames.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Wrapping things in single quotes and replacing all instances of ' with '"'"' covers all cases as far as I know.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Starting Directory... | Oddity007 | 2 | 2,315 |
Dec 13, 2009 10:30 AM Last Post: OneSadCookie |
|
| xCode "Copy Files Build Phase" | hangt5 | 2 | 5,246 |
Oct 5, 2005 03:36 PM Last Post: hangt5 |
|
| Interface Builder: lost bindings on alt-drag/copy/.. | sheijk | 0 | 2,825 |
Jul 22, 2005 07:18 AM Last Post: sheijk |
|

