我有大约8500个PDF文件存储在我的服务器上.我想在子文件夹中像这样潜水:
我知道如何创建一个新目录并在文件夹之间移动文件.但是检测哪些文件夹放置它们的最佳方法是什么.第二,如何使用正确的if函数来查看它们是否存在于某个文件夹中.
这样的东西可能有效(未经测试)
<?php
$listOfFiles = ["100.pdf", "200.pdf", "201.pdf"]; // populate this using glob / opendir
foreach ($listOfFiles as $file) {
// intval will return just the number part of the filename
// division with 100 + ceil will make 100 = 1, 200 = 2, 201 = 3 aso
$folderName = ceil(intval($file) / 100);
// make folder
if (!file_exists($folderName)) {
mkdir($folderName, 0755, true);
}
// move file if does not exists
if (!file_exists($foldername."/".$file)) {
rename($file, $foldername."/".$file);
} else {
// maybe delete it
unlink($file);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
81 次 |
| 最近记录: |