par
Jefekoi » 12 sept. 2021, 19:36
J'ai trouvé une autre source mais je n'arrive toujours à comptabiliser le nombre de fichier commençant par "444" ($compt)
<?php
$folder = "Mondossier";
//echo "<ul>";
list_files($folder);
//echo "</ul>";
// iterative function to read and list all the files and folders
function list_files($path) {
// Executing Opendir
$dir_handle = @opendir($path) or die("Unable to open $path");
// Extract the folder name in case it is a subdirectory
$dirname = (strpos('/', $path)) ? end(explode("/", $path)) : $path;
// Allowable files
$allowedExts = array("pdf", "doc", "docx", "txt", "jpg","jpeg", "png", "gif", "zip");
// Everything under this are either a file or a subdirectory
// echo ("<li>$dirname\n");
// Display the subfolder
// echo "<ul>\n";
// Loop through the files that existed in the folder
while (false !== ($file = readdir($dir_handle))) {
// Check if the name is not the current folder or root folder
if($file!="." && $file!="..") {
// Check if this file is a subdirectory
if (is_dir($path."/".$file)) {
// iterate if this is also a folder
list_files($path."/".$file);
} else {
// get the extension of the file
$extension = strtolower(pathinfo($file,PATHINFO_EXTENSION));
// check if extension is allowed
if (in_array($extension, $allowedExts)) {
// The file is allowed file
if (substr($file, 0, 3)=="444") {$compt++;}
}
}
}
} // end while
// Close the list
// echo "</ul>\n";
// echo "</li>\n";
echo "Total=".$compt."</br>";
//closing the directory
closedir($dir_handle);
}
?>
J'ai trouvé une autre source mais je n'arrive toujours à comptabiliser le nombre de fichier commençant par "444" ($compt)
[quote]
<?php
$folder = "Mondossier";
//echo "<ul>";
list_files($folder);
//echo "</ul>";
// iterative function to read and list all the files and folders
function list_files($path) {
// Executing Opendir
$dir_handle = @opendir($path) or die("Unable to open $path");
// Extract the folder name in case it is a subdirectory
$dirname = (strpos('/', $path)) ? end(explode("/", $path)) : $path;
// Allowable files
$allowedExts = array("pdf", "doc", "docx", "txt", "jpg","jpeg", "png", "gif", "zip");
// Everything under this are either a file or a subdirectory
// echo ("<li>$dirname\n");
// Display the subfolder
// echo "<ul>\n";
// Loop through the files that existed in the folder
while (false !== ($file = readdir($dir_handle))) {
// Check if the name is not the current folder or root folder
if($file!="." && $file!="..") {
// Check if this file is a subdirectory
if (is_dir($path."/".$file)) {
// iterate if this is also a folder
list_files($path."/".$file);
} else {
// get the extension of the file
$extension = strtolower(pathinfo($file,PATHINFO_EXTENSION));
// check if extension is allowed
if (in_array($extension, $allowedExts)) {
// The file is allowed file
if (substr($file, 0, 3)=="444") {$compt++;}
}
}
}
} // end while
// Close the list
// echo "</ul>\n";
// echo "</li>\n";
echo "Total=".$compt."</br>";
//closing the directory
closedir($dir_handle);
}
?>
[/quote]