我编写了以下代码来计算特定路径中的文件数。代码运行得很好,但FilesystemIterator也在计算我路径中的目录 - 这是我不想要的。我找不到如何指示FilesystemIterator“跳过”计数文件夹的方法。
<?php
$path = "\\\\192.168.10.14\\reservations";
$user = "user";
$pass = "pass";
$drive_letter = "Q";
system("net use ".$drive_letter.": \"".$path."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
$location = $drive_letter.":/";
$fi = new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS);
$fileCount = iterator_count($fi);
echo $fileCount;
?>
答案 0 :(得分:0)
我已经解决了这个问题如下:
<?php
$path = "\\\\192.168.10.14\\reservations";
$user = "user";
$pass = "user";
$drive_letter = "Q";
system("net use ".$drive_letter.": \"".$path."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
$location = $drive_letter.":/";
$objects = new RecursiveDirectoryIterator($path);
$fileCount = iterator_count($objects);
echo $fileCount;
?>