\func{}{wxFileName}{\param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{const wxString\& }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
-Constructor from a directory name, file base name and extension
+Constructor from a directory name, base file name and extension
+
+\func{}{wxFileName}{\param{const wxString\& }{volume}, \param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{const wxString\& }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
+
+Constructor from a volume name, a directory name, base file name and extension
\membersection{wxFileName::AppendDir}\label{wxfilenameappenddir}
\func{void}{AssignDir}{\param{const wxString\& }{dir}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
-empty volume
-
+Set this file name object to the given directory name. The name and extension
+will be empty.
\membersection{wxFileName::AssignHomeDir}\label{wxfilenameassignhomedir}
\func{void}{AssignHomeDir}{\void}
-get the value of user home (Unix only mainly)
-
+Set this file name object to the home directory.
\membersection{wxFileName::AssignTempFileName}\label{wxfilenameassigntempfilename}
wxPathFormat format = wxPATH_NATIVE)
{ Assign(path, name, format); }
+ // from a volume, directory name, file base name and extension
+ wxFileName(const wxString& volume,
+ const wxString& path,
+ const wxString& name,
+ const wxString& ext,
+ wxPathFormat format = wxPATH_NATIVE)
+ { Assign(volume, path, name, ext, format); }
+
// from a directory name, file base name and extension
wxFileName(const wxString& path,
const wxString& name,
#include "wx/filename.h"
+static void DumpFileName(const wxFileName& fn)
+{
+ wxString full = fn.GetFullPath();
+
+ wxString vol, path, name, ext;
+ wxFileName::SplitPath(full, &vol, &path, &name, &ext);
+
+ wxPrintf(_T("Filename '%s' -> vol '%s', path '%s', name '%s', ext '%s'\n"),
+ full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str());
+}
+
static struct FileNameInfo
{
const wxChar *fullname;
#endif // TEST_FILE
#ifdef TEST_FILENAME
- TestFileNameTemp();
+ if ( 0 )
+ {
+ wxFileName fn;
+ fn.Assign("c:\\foo", "bar.baz");
+
+ DumpFileName(fn);
+ }
+
if ( 0 )
{
TestFileNameConstruction();
TestFileNameSplit();
+ TestFileNameTemp();
TestFileNameCwd();
TestFileNameComparison();
TestFileNameOperations();
Assign(volume, path, name, ext, format);
}
-void wxFileName::Assign(const wxString& fullpath,
+void wxFileName::Assign(const wxString& fullpathOrig,
const wxString& fullname,
wxPathFormat format)
{
+ // always recognize fullpath as directory, even if it doesn't end with a
+ // slash
+ wxString fullpath = fullpathOrig;
+ if ( !wxEndsWithPathSeparator(fullpath) )
+ {
+ fullpath += GetPathSeparators(format)[0u];
+ }
+
wxString volume, path, name, ext;
+
+ // do some consistency checks in debug mode: the name should be really just
+ // the filename and the path should be realyl just a path
+#ifdef __WXDEBUG__
+ wxString pathDummy, nameDummy, extDummy;
+
+ SplitPath(fullname, &pathDummy, &name, &ext, format);
+
+ wxASSERT_MSG( pathDummy.empty(),
+ _T("the file name shouldn't contain the path") );
+
+ SplitPath(fullpath, &volume, &path, &nameDummy, &extDummy, format);
+
+ wxASSERT_MSG( nameDummy.empty() && extDummy.empty(),
+ _T("the path shouldn't contain file name nor extension") );
+
+#else // !__WXDEBUG__
SplitPath(fullname, NULL /* no path */, &name, &ext, format);
SplitPath(fullpath, &volume, &path, NULL, NULL, format);
+#endif // __WXDEBUG__/!__WXDEBUG__
Assign(volume, path, name, ext, format);
}
void wxFileName::AssignDir(const wxString& dir, wxPathFormat format)
{
- // always recognize dir as directory, even if it doesn't end with a slash
- wxString dirname = dir;
- if ( !wxEndsWithPathSeparator(dirname) )
- {
- dirname += GetPathSeparators(format)[0u];
- }
-
- Assign(dirname, _T(""), format);
+ Assign(dir, _T(""), format);
}
void wxFileName::Clear()