Directory Merging

Status
Not open for further replies.

Enigmabomb

New member
Feb 26, 2007
2,035
66
0
Than Franthithco
Challenge: Keep a mirror of a directory on unix

Example:


DIR 1: DIR 2:

1.jpg 1.jpg
2.jpg 2.jpg
3.jpg


I want a script/command/ whatever that will make DIR 2 have 3.jpg.

You may ask why not just rm dir 2, then cp dir 1 to wher DIR 2 lives. Answer: There are 100k files.

Thanks in advance.

Josh
 


i'd do that with php:

Code:
function copyDir($source_directory, $destination_directory) 
{
    //handler for the directory
    $handler = opendir($source_directory);
    //read all files in the directory
    while($file = readdir($handler)) 
    {
        //check file extension
        if(strtolower(substr($file, strpos($file, '.')+1))=='jpg')
        {
            //copy if file with the same name doesnt exist in the destination dir
            if(!file_exists($destination_directory.'/'.$file))
                copy($file, $destination_directory.'/'.$file);
        }                                
    }
    //close the handler
    closedir($handler);
}
set a cron if you want to run the script periodically
 
Status
Not open for further replies.