Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to move all the files from one directory to another in PHP

1 Answer

0 votes
function move_files($src, $dst) 
{ 
    $handle = opendir($src);                     
    if (!is_dir($dst)) mkdir($dst, 0755);  

    while ($file = readdir($handle)) 
    { 
        if (($file != ".") and ($file != "..")) 
        {       
            $src_path = $src."/".$file; 
            $dst_path = $dst."/".$file; 
            if (is_dir($src_path)) 
            {                     
                move_files($src_path, $dst_path);               
            } 
            else 
            { 
                copy($src_path, $dst_path); 
                unlink($src_path);                        
            }                                            
        } 
    } 
    closedir($handle); 
    rmdir($src);                                    
} 

move_files("d:\\test", "d:\\test_1");


answered Aug 31, 2014 by avibootz

Related questions

2 answers 203 views
1 answer 211 views
1 answer 170 views
1 answer 202 views
3 answers 256 views
3 answers 243 views
...