开发者

How to get the extension of a file? PHP command line

开发者 https://www.devze.com 2023-03-23 05:42 出处:网络
I\'m making a CLI script that mass renames files, however I do not kno开发者_如何学Gow how to get the extension of a file that I don\'t know the extension of... Basically the CSV file I have is laid o

I'm making a CLI script that mass renames files, however I do not kno开发者_如何学Gow how to get the extension of a file that I don't know the extension of... Basically the CSV file I have is laid out like so:

"New filename", "oldfile",
"New filename", "oldfile"

No extension is given on the old file. How would I go about doing this? I would greatly appreciate the help.


pathinfo will return an array which includes that information. You're specifically looking for the key 'extension'.

<?php
// from http://php.net/manual/en/function.pathinfo.php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');

echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消