0
我想检索目录文件夹中的所有文件夹并更改其中的所有子文件夹。例如, 在根文件夹Root中,我想将所有子文件夹A,B,C,D,..更改为1,2,34,...我可以知道如何使用php来完成此操作吗?谢谢。检索目录中的所有文件夹并更改其中的所有文件夹名称
我想检索目录文件夹中的所有文件夹并更改其中的所有子文件夹。例如, 在根文件夹Root中,我想将所有子文件夹A,B,C,D,..更改为1,2,34,...我可以知道如何使用php来完成此操作吗?谢谢。检索目录中的所有文件夹并更改其中的所有文件夹名称
事情是这样的:
$count = 0;
foreach(new DirectoryIterator('Root') as $fileInfo) {
if ($fileInfo->isDir() && !$fileInfo->isDot()) {
$count++;
rename($fileInfo->getPathName(), $fileInfo->getPath() . "/$count");
}
}
DirectoryIterator
rename
RecursiveDirectoryIterator
(如果你做的子目录相同)<?php
$basedir = "/tmp"; //or whatever your "to change" home directory is
$contents = scandir($basedir);
$count = 1;
foreach ($contents as $check) {
if (is_dir($basedir . "/" . $check) && $check != "." && $check != "..") {
rename($basedir . "/" . $check, $basedir . "/" . $count);
$count++;
}
}
?>
当然,您需要拥有正确的CHMOD,具体取决于您从哪里运行脚本。
你到目前为止尝试过什么?为了让你走上正确的轨道,你需要看看'scandir','is_dir'和'rename'功能。 –