From f0ce3409421a7c5c800a2255295274187220e8de Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Mon, 26 Mar 2001 13:31:12 +0000 Subject: [PATCH] Added 'full' param to wxFileName::Mkdir to make all directories in a path, not just the last one git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9583 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/filename.h | 7 ++++--- src/common/filename.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/include/wx/filename.h b/include/wx/filename.h index 0f3153b65b..cf6cd1d18e 100644 --- a/include/wx/filename.h +++ b/include/wx/filename.h @@ -166,9 +166,10 @@ public: // get a temp file name starting with thespecified prefix void AssignTempFileName( const wxString &prefix ); - // directory creation and removal - bool Mkdir( int perm = 0777 ); - static bool Mkdir( const wxString &dir, int perm = 0777 ); + // 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 Rmdir(); static bool Rmdir( const wxString &dir ); diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 342bdb88e2..610a7c2993 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -204,14 +204,46 @@ void wxFileName::AssignTempFileName( const wxString &prefix ) // directory operations // ---------------------------------------------------------------------------- -bool wxFileName::Mkdir( int perm ) +bool wxFileName::Mkdir( int perm, bool full ) { - return wxFileName::Mkdir( GetFullPath(), perm ); + return wxFileName::Mkdir( GetFullPath(), perm, full ); } -bool wxFileName::Mkdir( const wxString &dir, int perm ) +bool wxFileName::Mkdir( const wxString &dir, int perm, bool full ) { - return ::wxMkdir( dir, perm ); + if (full) + { + wxFileName filename(dir); + wxArrayString dirs = filename.GetDirs(); + + size_t count = dirs.GetCount(); + size_t i; + wxString currPath; + int noErrors = 0; + for ( i = 0; i < count; i++ ) + { + 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; + } + + return (noErrors == 0); + + } + else + return ::wxMkdir( dir, perm ); } bool wxFileName::Rmdir()