Solved

php move all files from one folder to another

Posted on 2009-05-18
3
3,480 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
3 Comments
 
LVL 4

Accepted Solution

by:
bljak earned 500 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 109

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
paypal ipn to mysql 3 35
PHP populating an array. 4 23
Google Maps API and PHP 25 27
Number of hours between date in DB and now 8 14
This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

785 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