Page 1 of 1

To handle directories. I am new in php.

Posted: Thu Jul 29, 2004 1:41 pm
by akosko
Please help me with this issue. I would like to copy whole not empty directory to a destination folder but I do not know whether is there any possible way to do it with one copy command. Could you advise what to do ? Should I all the files and directories read first ? There is a lot of file and directories and deep structure of directories under this director I need to copy. Thanks :?

Posted: Thu Jul 29, 2004 1:56 pm
by feyd
using [php_man]glob[/php_man]() or a combo of [php_man]opendir[/php_man]()/[php_man]readdir[/php_man]() will get you the file list, if any, in that directory.

using [php_man]copy[/php_man]() and a loop like [php_man]foreach[/php_man]() or [php_man]while[/php_man]() you can copy each file over to the new folder.

Posted: Thu Jul 29, 2004 2:05 pm
by akosko
Great, thank you. It seems to be quite simple but what about the directory structure. Do I need to handle the directories one after another and so on go deeper and deeper ?

Posted: Thu Jul 29, 2004 2:31 pm
by feyd
yes.. You may want a recursive iterator like a TreeIterator.