diff --git a/cake/libs/file.php b/cake/libs/file.php index c940bbd1f..274371a3d 100644 --- a/cake/libs/file.php +++ b/cake/libs/file.php @@ -163,6 +163,15 @@ class File extends Object{ $size = filesize($this->pwd()); return $size; } +/** + * Returns the File extension. + * + * @return string The File extension + * @access public + */ + function info() { + return pathinfo($this->pwd()); + } /** * Returns the File extension. * @@ -170,16 +179,25 @@ class File extends Object{ * @access public */ function ext() { - $ext = ''; - $parts = explode('.', $this->name); - - if (count($parts) > 1) { - $ext = array_pop($parts); - } else { - $ext = ''; + $info = $this->info(); + if(isset($info['extension'])) { + return $info['extension']; } - return $ext; + return false; } +/** + * Returns the File name without extension. + * + * @return string The File name without extension. + * @access public + */ + function filename() { + $info = $this->info(); + if(isset($info['filename'])) { + return $info['filename']; + } + return false; + } /** * Returns the File's owner. * diff --git a/cake/tests/cases/libs/file.test.php b/cake/tests/cases/libs/file.test.php index 2f4b04a60..6d4c05e14 100644 --- a/cake/tests/cases/libs/file.test.php +++ b/cake/tests/cases/libs/file.test.php @@ -50,10 +50,19 @@ class FileTest extends UnitTestCase { $result = $this->File->name; $expecting = basename(__FILE__); $this->assertEqual($result, $expecting); - + + $result = $this->File->info(); + $expecting = array('dirname'=> dirname(__FILE__), 'basename'=> basename(__FILE__), + 'extension'=> 'php', 'filename'=> 'file.test'); + $this->assertEqual($result, $expecting); + $result = $this->File->ext(); $expecting = 'php'; $this->assertEqual($result, $expecting); + + $result = $this->File->filename(); + $expecting = 'file.test'; + $this->assertEqual($result, $expecting); $result = $this->File->md5(); $expecting = md5_file($file);