fixed several bugs in Mkdir() and also modified its API to be more user friendly (based on the patch 541033 from Chris Elliott)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-04-08 16:28:50 +00:00
parent 33b97389e5
commit 1527281edb
3 changed files with 39 additions and 30 deletions

View File

@@ -539,15 +539,17 @@ different from the volume specified by {\it pathBase}).
\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{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.}
\wxheading{Return value}

View File

@@ -80,6 +80,12 @@ enum
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
// ----------------------------------------------------------------------------
@@ -236,8 +242,8 @@ public:
// 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 );

View File

@@ -735,47 +735,48 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
// 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 (full)
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;
wxString currPath;
int noErrors = 0;
for ( i = 0; i < count; i++ )
if ( filename.HasVolume())
{
currPath << wxGetVolumeString(filename.GetVolume(), wxPATH_NATIVE);
}
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 += dirs[i];
if (currPath.Last() == wxT(':'))
{
// Can't create a root directory so continue to next dir
currPath += wxFILE_SEP_PATH;
continue;
}
if (!DirExists(currPath))
{
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);
return TRUE;
}
else
return ::wxMkdir( dir, perm );
return ::wxMkdir( dir, perm );
}
bool wxFileName::Rmdir()