Copy language directory

Posted on Jun 27, 2010 in Code, Tips & Tricks | 0 comments

I test Elgg themes, widgets and language files on localhost, and occasionally need to do a clean Elgg installation. Once done, all language files, more than 36 must be moved to the proper folders.

Not a big deal but this little function can do the job and copy an entire directory with language files to the new elgg installation. Just insert the paths to source and destination directories and run the script, then your language files will be copied to the appropriate folders.

$src = 'path/'; 
$dst = 'path/'; 

function recurse_copy($src,$dst) {
    $dir = opendir($src);
    @mkdir($dst);
    while(false !== ( $file = readdir($dir)) ) {
        if (( $file != '.' ) && ( $file != '..' )) {
            if ( is_dir($src . '/' . $file) ) {
                recurse_copy($src . '/' . $file,$dst . '/' . $file);
            }
            else {
                copy($src . '/' . $file,$dst . '/' . $file);				
            }			
        }
    }
    closedir($dir);	
}
recurse_copy($src,$dst);

Use the function with caution and remember that all files in the source directory will be copied to the new directory overwriting the old files.

You can copy paste the function or download the package with an index.php with a form where you can fill in the directory paths.

Leave a Comment

Your email address will not be published. Required fields are marked *

Anti-Spam Quiz: