移动以 AD、EG、HL、MP、QT、UW 和 XZ 开头的文件

发布于 11-19 21:09 字数 221 浏览 7 评论 0原文

我的文件夹中有数百万个文件,很难用脚本读取,所以我需要将文件存储在单独的文件夹中。 一样

就像将文件移动到 AD、EG、HL、MP、QT、UW 和 XZ 并带有起始字符

。我尝试使用 FTP,但数以百万计的文件没有正确显示在目录中(显示和移动需要很长时间,有时 FTP 卡住了),也尝试了 cpanel 等,但没有运气。

如果有 PHP 脚本的解决方案请告诉我,它对我有很大帮助。

I have millions of file in a Folder its difficult to read with script so i need to store file in separate folder. just like

Move File to A-D and E-G and H-L and M-P and Q-T and U-W and X-Z with there starting character..

I try to use FTP but million so file did not show in directory correctly (took very long time to display and for moving, some time FTP stuck), also try cpanel etc. but no luck.

if there is a solution with PHP script please let me know, its help me alot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱猫软卧2024-11-26 21:09:37

好吧,您可以使用 DirectoryIterator 并移动基于文件名的文件。我仍然宁愿推荐使用 SSH 或类似的更直接的方法(有些事情 PHP 不应该做 - 比如非网站的事情);这种做法是Remote Client --request--> Web服务器--访问-->文件系统。

除此之外,类似“

$dirname = dirname(__FILE__);
$iterator = new DirectoryIterator($dirname);

foreach ($iterator as $fileinfo) {
    if ($fileinfo->isFile() && $fileinfo->isWritable()) {
        $fname = $fileinfo->getFilename();
        rename($dirname. DIRECTORY_SEPARATOR .$fname, $dirname. DIRECTORY_SEPARATOR .ucfirst(substr($fname, 0, 1)). DIRECTORY_SEPARATOR .$fname);
    }
}

应该将文件移动到与文件名中第一个字符相同的字母的子目录中”。如果您想根据字符类别组进行移动,只需将 rename() 调用放入 switch 语句中即可。

Well, you could use DirectoryIterator and move the files based on the filename. I'd still rather recommend a more direct approach with SSH or similar (there are things PHP wasn't meant to do - like non-website things); this approach is Remote Client --request--> Web Server --access--> File System.

Other than that, something like

$dirname = dirname(__FILE__);
$iterator = new DirectoryIterator($dirname);

foreach ($iterator as $fileinfo) {
    if ($fileinfo->isFile() && $fileinfo->isWritable()) {
        $fname = $fileinfo->getFilename();
        rename($dirname. DIRECTORY_SEPARATOR .$fname, $dirname. DIRECTORY_SEPARATOR .ucfirst(substr($fname, 0, 1)). DIRECTORY_SEPARATOR .$fname);
    }
}

Should move the files into a subdirectory with the same letter as the first character in the filename. If you want to move based on category groups of characters, just put the rename() call into a switch statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文