Move file into a specific folder
<p>I have a question regarding file handle, i have:</p>

<p>Files:
 "Mark, 123456, HTCOM.pdf"</p>

<p>"John, 409721, JESOA.pdf</p>

<p>Folders:</p>

<p>"Mark, 123456"</p>

<p>"Mark, 345212"</p>

<p>"Mark, 645352"</p>

<p>"John, 409721"</p>

<p>"John, 235212"</p>

<p>"John, 124554"</p>

<p>I need a routine to move files to correct folders.
In case above, i need to compare 1st and second value from file and folder. If are the same i move the file.</p>

<p>Complement to post:
I have this code, work right but i need to modify to check name and code to move files...
I'm confused to implement function...</p>

<pre><code>$pathToFiles = 'files folder'; 
$pathToDirs  = 'subfolders'; 
foreach (glob($pathToFiles . DIRECTORY_SEPARATOR . '*.pdf') as $oldname) 
{ 
    if (is_dir($dir = $pathToDirs . DIRECTORY_SEPARATOR . pathinfo($oldname, PATHINFO_FILENAME)))
     { 
        $newname = $dir . DIRECTORY_SEPARATOR . pathinfo($oldname, PATHINFO_BASENAME);


        rename($oldname, $newname); 
    } 
}
</code></pre>
