E.g:
folder name:
myFonlder
files in myFolder
myFolder.01.mkv
myFolder.02.mkv
myFolder.03.avi
myFolder.04.mts
...
// each file's extension may be different.
So,how can I extract the extension of each file?
Thank you very much!!
[update]
my own solution; want to know is it fast enough!?
foreach (glob("d:\\myFolder\\*.*") as $filename) {
//echo "$filename size " . filesize($filename) . "
";
$path_parts = pathinfo($filename);
echo $path_parts['dirname'], "
";
echo $path_parts['basename'], "
";
echo $path_parts['extension'], "
";
echo $path_parts['filename'], "
"; // since PHP 5.2.0
}
<?php
foreach (new DirectoryIterator('../moodle') as $fileInfo) {
if($fileInfo->isDot()) continue;
echo $fileInfo->getFilename() . "<br>
";
}
?>
And use http://www.php.net/manual/en/function.pathinfo.php on filename
This is the quick and easy solution on windows.
exec("dir d:\directory_name /b" ,$output); // in Linux dir will change to ls
foreach($output as $file_name){
$file_parts = explode(".",$file_name);
echo "File Name : ".$file_parts[0]."
";
echo "File Extension : ".$file_parts[1]."
";
}
Enjoy..!!