Commit 5bdb986e authored by hybrid's avatar hybrid

Added a method to get the basename of the file, without path.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1281 dfc29bdd-3216-0410-991c-e03cc46cb475
parent e7add518
......@@ -119,6 +119,11 @@ public:
/** \param filename: The file to get the directory from */
virtual core::stringc getFileDir(const core::stringc& filename) const = 0;
//! Returns the base part of a filename, i.e. the name without the directory
//! part. If no directory is prefixed, the full name is returned.
/** \param filename: The file to get the basename from */
virtual core::stringc getFileBasename(const core::stringc& filename) const = 0;
//! Creates a list of files and directories in the current working directory and returns it.
/** \return a Pointer to the created IFileList is returned. After the list has been used
it has to be deleted using its IFileList::drop() method.
......
......@@ -238,6 +238,10 @@ core::stringc CFileSystem::getAbsolutePath(const core::stringc& filename) const
return ret;
}
//! returns the directory part of a filename, i.e. all until the first
//! slash or backslash, excluding it. If no directory path is prefixed, a '.'
//! is returned.
core::stringc CFileSystem::getFileDir(const core::stringc& filename) const
{
// find last forward or backslash
......@@ -251,6 +255,23 @@ core::stringc CFileSystem::getFileDir(const core::stringc& filename) const
return ".";
}
//! returns the base part of a filename, i.e. all except for the directory
//! part. If no directory path is prefixed, the full name is returned.
core::stringc CFileSystem::getFileBasename(const core::stringc& filename) const
{
// find last forward or backslash
s32 lastSlash = filename.findLast('/');
const s32 lastBackSlash = filename.findLast('\\');
lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
if ((u32)lastSlash < filename.size())
return filename.subString(lastSlash+1, filename.size()-lastSlash);
else
return filename;
}
//! Creates a list of files and directories in the current working directory
IFileList* CFileSystem::createFileList() const
{
......
......@@ -62,6 +62,11 @@ public:
/** \param filename: The file to get the directory from */
virtual core::stringc getFileDir(const core::stringc& filename) const;
//! Returns the base part of a filename, i.e. the name without the directory
//! part. If no directory is prefixed, the full name is returned.
/** \param filename: The file to get the basename from */
core::stringc getFileBasename(const core::stringc& filename) const;
//! Creates a list of files and directories in the current working directory
//! and returns it.
virtual IFileList* createFileList() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment