Added 'full' param to wxFileName::Mkdir to make all directories in a path,
authorJulian Smart <julian@anthemion.co.uk>
Mon, 26 Mar 2001 13:31:12 +0000 (13:31 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Mon, 26 Mar 2001 13:31:12 +0000 (13:31 +0000)
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
src/common/filename.cpp

index 0f3153b65be4536a10c975d56ba30c181dbe225d..cf6cd1d18e74fb6a43d84019d1a7ae83c1babe05 100644 (file)
@@ -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 );
index 342bdb88e288bbf0fda86110f4349c3361b4c415..610a7c2993a5abd10055329c2ffb7e42a8f5d251 100644 (file)
@@ -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()