How to copy directory

Linux specific questions.
Post Reply
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

How to copy directory

Post by nimdays »

Do you have any idea how to copy directory and subdir like cp from shell with Api ?
I know how to move and delete dir and subdir.

Thanks.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: How to copy directory

Post by caseih »

You could use system to run cp -r or rsync -r.

If you want to stick to pure FB code, you'll have to do it all yourself. Walk the directory tree, if an item is a directory, recurse into it.
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: How to copy directory

Post by nimdays »

caseih wrote:You could use system to run cp -r or rsync -r.

If you want to stick to pure FB code, you'll have to do it all yourself. Walk the directory tree, if an item is a directory, recurse into it.
Thanks, Maybe system is the solution for now.
Dir plus subdir and files,sorry.

I read how to delete with ntfw from here:
https://stackoverflow.com/questions/546 ... in-posix-c
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: How to copy directory

Post by caseih »

You can do a copy in much the same way, using nftw. Rather than unlinking a file, you would copy it. Of course you have to do the copy yourself also, by opening the source and target and reading and writing chunks of data. Then of course set the permissions. I don't know of any function that copies files, but I bet there is something in a library somewhere.
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: How to copy directory

Post by nimdays »

caseih wrote:You can do a copy in much the same way, using nftw. Rather than unlinking a file, you would copy it. Of course you have to do the copy yourself also, by opening the source and target and reading and writing chunks of data. Then of course set the permissions. I don't know of any function that copies files, but I bet there is something in a library somewhere.
Thanks again, It's really helpful.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: How to copy directory

Post by caseih »

So this post may be relevant: https://stackoverflow.com/questions/919 ... linux-unix

ntfw can do it, but your callback will need some way of knowing what the target path is, since it's not part of the callback mechanism. A global variable would do it, but that's not so clean in my opinion. Perhaps you can recursively scan the files yourself using FB's builtin DIR() function.
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: How to copy directory

Post by nimdays »

caseih wrote:So this post may be relevant: https://stackoverflow.com/questions/919 ... linux-unix

ntfw can do it, but your callback will need some way of knowing what the target path is, since it's not part of the callback mechanism. A global variable would do it, but that's not so clean in my opinion. Perhaps you can recursively scan the files yourself using FB's builtin DIR() function.
Thanks again,
There is one problem with this ntfw, i/o error message after several dirs if the source path is root(/).
Maybe with dir like you said and filecopy will do it.
Post Reply