我有大量书籍需要按语言和 libraryID 进行分类。
文件名的结构是这样的,并分布在许多文件夹中:
ENG_FILENAME_LIBRARYNAME1.pdf
ENG_FILENAME_LIBRARYNAME2.pdf
SPA_FILENAME_LIBRARYNAME1.pdf
SPA_FILENAME_LIBRARYNAME2.pdf
我需要将它们移动到这样的文件夹中
ENG
->LIBRARYNAME1
--ENG_FILENAME_LIBRARYNAME1.pdf
->LIBRARYNAME2
--ENG_FILENAME_LIBRARYNAME2.pdf
这是我的代码:
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);
}
}
}
}
}
提前致谢!