git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15033
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
\membersection{wxFileName::Mkdir}\label{wxfilenamemkdir}
\membersection{wxFileName::Mkdir}\label{wxfilenamemkdir}
-\func{bool}{Mkdir}{\param{int }{perm = 0777}, \param{bool }{full = FALSE}}
+\func{bool}{Mkdir}{\param{int }{perm = 0777}, \param{int }{flags = $0$}}
-\func{static bool}{Mkdir}{\param{const wxString\& }{dir}, \param{int }{perm = 0777}, \param{bool }{full = FALSE}}
+\func{static bool}{Mkdir}{\param{const wxString\& }{dir}, \param{int }{perm = 0777}, \param{int }{flags = $0$}}
\docparam{dir}{the directory to create}
\docparam{parm}{the permissions for the newly created directory}
\docparam{dir}{the directory to create}
\docparam{parm}{the permissions for the newly created directory}
-\docparam{full}{if {\tt TRUE}, will try to make each directory in the path}
+\docparam{flags}{if the flags contain {\tt wxPATH\_MKDIR\_FULL} flag,
+try to create each directory in the path and also don't return an error
+if the target directory already exists.}
wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator
};
wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator
};
+// MkDir flags
+enum
+{
+ wxPATH_MKDIR_FULL = 0x0001 // create directories recursively
+};
+
// ----------------------------------------------------------------------------
// wxFileName: encapsulates a file path
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxFileName: encapsulates a file path
// ----------------------------------------------------------------------------
// directory creation and removal.
// if full is TRUE, will try to make each directory in the path.
// directory creation and removal.
// if full is TRUE, will try to make each directory in the path.
- bool Mkdir( int perm = 0777, bool full = FALSE);
- static bool Mkdir( const wxString &dir, int perm = 0777, bool full = FALSE );
+ bool Mkdir( int perm = 0777, int flags = 0);
+ static bool Mkdir( const wxString &dir, int perm = 0777, int flags = 0 );
bool Rmdir();
static bool Rmdir( const wxString &dir );
bool Rmdir();
static bool Rmdir( const wxString &dir );
// directory operations
// ----------------------------------------------------------------------------
// directory operations
// ----------------------------------------------------------------------------
-bool wxFileName::Mkdir( int perm, bool full )
+bool wxFileName::Mkdir( int perm, int flags )
- return wxFileName::Mkdir( GetFullPath(), perm, full );
+ return wxFileName::Mkdir( GetFullPath(), perm, flags );
-bool wxFileName::Mkdir( const wxString &dir, int perm, bool full )
+bool wxFileName::Mkdir( const wxString& dir, int perm, int flags )
+ if ( flags & wxPATH_MKDIR_FULL )
- wxFileName filename(dir);
- wxArrayString dirs = filename.GetDirs();
- dirs.Add(filename.GetName());
+ // split the path in components
+ wxFileName filename;
+ filename.AssignDir(dir);
- size_t count = dirs.GetCount();
- size_t i;
- int noErrors = 0;
- for ( i = 0; i < count; i++ )
- {
- currPath += dirs[i];
+ if ( filename.HasVolume())
+ {
+ currPath << wxGetVolumeString(filename.GetVolume(), wxPATH_NATIVE);
+ }
- if (currPath.Last() == wxT(':'))
- {
- // Can't create a root directory so continue to next dir
+ wxArrayString dirs = filename.GetDirs();
+ size_t count = dirs.GetCount();
+ for ( size_t i = 0; i < count; i++ )
+ {
+ if ( i > 0 || filename.IsAbsolute() )
currPath += wxFILE_SEP_PATH;
currPath += wxFILE_SEP_PATH;
if (!DirExists(currPath))
if (!DirExists(currPath))
if (!wxMkdir(currPath, perm))
if (!wxMkdir(currPath, perm))
- noErrors ++;
-
- if ( (i < (count-1)) )
- currPath += wxFILE_SEP_PATH;
+ {
+ // no need to try creating further directories
+ return FALSE;
+ }
+ }
- return (noErrors == 0);
- else
- return ::wxMkdir( dir, perm );
+
+ return ::wxMkdir( dir, perm );
}
bool wxFileName::Rmdir()
}
bool wxFileName::Rmdir()