View Single Post
Old 05-15-2008, 08:45 AM  
ScriptWorkz
Confirmed User
 
Industry Role:
Join Date: Jul 2007
Location: Intraweb
Posts: 274
PHP Code:
#!/usr/bin/php
<?
// set $base_dir to the source dir, and $dest_dir to where you want files moved too, include trailing /
$base_dir = "/source/dir/";
$dest_dir = "/dest/dir/";

// function for recursion
function process_dir($dir) {
    global $dest_dir;
    
    $d = opendir($dir);
    
    while (($f = readdir($d)) !== FALSE) {
        if (strcmp($f, ".") && strcmp($f, "..")) {
            if (is_dir($dir . $f)) {
                process_dir($dir . $f);
            } else if (is_file($dir . $f)) {
                $tmp = explode(".", $f);
                $ext = strtolower($tmp[(count($tmp) - 1)]);
            
                if (!strcmp($ext, "jpg") || !strcmp($ext, "jpeg")) {
                    // to copy files
                    copy($dir . $f, $dest_dir . $f);
                
                    // uncomment to move files instead, comment above
                    // rename($dir . $f, $dest_dir . $f)
                }
            }
        }
    }
    
    closedir($d);
}

process_dir($base_dir);
?>
i didn't test it, but if you save that as say move-pics.php and chmod it +x then ./move-pics.php it should do the trick. if you want files moved instead of copied, look at the comments and comment the copy line out and remove the commenting on the rename line. you also need to make sure the shebang at the top points to your php binary and the $base_dir and $dest_dir variables are set to your x and y directories respectively.

EDIT: just saw mike souths post, as a shell script that'd probably work a little easier then mine, atleast you have a backup.

Last edited by ScriptWorkz; 05-15-2008 at 08:47 AM..
ScriptWorkz is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote