Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

php move all files from one folder to another

Posted on 2009-05-18
3
Medium Priority
?
3,610 Views
Last Modified: 2013-12-12
hello again...

i'm needing to add all contents from one folder to another using php. then delete the source.
source folder holds over 6,000 files..

does anybody have any ideas?

Ive tried the following with no luck..


<?
$directoryToMove = opendir("../folder1/innerFolder/");
// get each entry
while($entryName = readdir($directoryToMove)) {
	rename("sourcePath;", "newPath/");
}
 
 
?>

Open in new window

0
Comment
Question by:Cybervanes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
bljak earned 2000 total points
ID: 24418749

<?
$sourceDir = "../folder1/innerFolder/";
$targetDir = "../folder2/innerFolder/";
 
if ( $dh = opendir($sourceDir) )
{
    while(false !== ($fileName = readdir($dh)))
    {
        if (!in_array($fileName, array('.','..')))
        {
            rename($sourceDir.$fileName, $targetDir.$fileName);
        }
    }
}
 
 
?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24425170
Can you just rename the folder?  Or are you adding files to an existing folder?  What do you want to do about filename collisions?  Keep the oldest or the newest, or overwrite the older with the new?

6,000 files is probably no trouble at all unless these are gigantic files.
0
 
LVL 2

Author Closing Comment

by:Cybervanes
ID: 31582871
Worked Good Thank You!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question