Copying a directory tree

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
limonada
Forum Newbie
Posts: 11
Joined: Sat Oct 08, 2005 7:23 am

Copying a directory tree

Post by limonada »

Hello! Does anyone have a script for copying a directory tree from one place to another? Or if somebody can give me some hints how to do it... Thanks!
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

You could perhaps use readdir() and loop through the files and directories.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

In my experience, you don't need to worry about copying every file in the directory tree, just the directory at the top. For example, if you have a directory: /var/www/html/ and you want to copy every file in that directory, just copy that directory and each file underneath will be copied as well.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
limonada
Forum Newbie
Posts: 11
Joined: Sat Oct 08, 2005 7:23 am

Post by limonada »

does this apply to the subdirectories too,or just the files in the directory?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Subdirectories should be copied too
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
limonada
Forum Newbie
Posts: 11
Joined: Sat Oct 08, 2005 7:23 am

Post by limonada »

ok! thanks!
Post Reply