To handle directories. I am new in php.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
akosko
Forum Newbie
Posts: 3
Joined: Mon Jul 26, 2004 1:06 am

To handle directories. I am new in php.

Post 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 :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
akosko
Forum Newbie
Posts: 3
Joined: Mon Jul 26, 2004 1:06 am

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes.. You may want a recursive iterator like a TreeIterator.
Post Reply