I have a large number of books that I need to categorize by language and libraryID.
The file-names are structured like this and spread out in many folders:
ENG_FILENAME_LIBRARYNAME1.pdf
ENG_FILENAME_LIBRARYNAME2.pdf
SPA_FILENAME_LIBRARYNAME1.pdf
SPA_FILENAME_LIBRARYNAME2.pdf
I need to move them into folders like this
ENG
->LIBRARYNAME1
--ENG_FILENAME_LIBRARYNAME1.pdf
->LIBRARYNAME2
--ENG_FILENAME_LIBRARYNAME2.pdf
Here's my code:
foreach (glob("C:/wamp/www/projects/filemove/eth/*") as $folderpath) {
$foldername = preg_replace('/.*?\/(.*?)/', '$1', $folderpath);
foreach (glob("C:/wamp/www/projects/filemove/eth/*/*") as $librarypath) {
$libraryname = preg_replace('/.*?\/(.*?)/', '$1', $librarypath);
foreach (glob("C:/wamp/www/projects/filemove/pdf/*.pdf") as $filepath) {
$ethologue = preg_replace('/(.*?)_.*/', '$1', $filepath);
$library = preg_replace('/.*?_.*?_.*?_(.*?)_.*/', '$1', $filepath);
$filename = preg_replace('/.*?\/(.*?)/', '$1', $filepath);
if ($ethologue = $foldername ) {
if ($library = $libraryname) {
copy($filepath, $librarypath);
}
}
}
}
}
Thanks in advance!