Copy directory

Apprentice
Posts: 19
Joined: 2008.05
Post: #1
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 ?
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #2
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.
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2008.05
Post: #3
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 fineSmile
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #4
That's the way I would do it. Totally koscher.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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.
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #6
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
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().
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
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.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #9
Wrapping things in single quotes and replacing all instances of ' with '"'"' covers all cases as far as I know.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Starting Directory... Oddity007 2 2,662 Dec 13, 2009 10:30 AM
Last Post: OneSadCookie
  xCode "Copy Files Build Phase" hangt5 2 6,226 Oct 5, 2005 03:36 PM
Last Post: hangt5
  Interface Builder: lost bindings on alt-drag/copy/.. sheijk 0 3,201 Jul 22, 2005 07:18 AM
Last Post: sheijk