How do I recursively create a folder in Win32?

前端 未结 14 1325
孤城傲影
孤城傲影 2020-12-01 14:11

I\'m trying to create a function that takes the name of a directory (C:\\foo\\bar, or ..\\foo\\bar\\..\\baz, or \\\\someserver\\foo\\bar

14条回答
  •  无人及你
    2020-12-01 14:31

    If you don't need to support Windows versions prior to Windows 2000, you can use the SHCreateDirectoryEx function for this. Consider this:

    int createDirectoryRecursively( LPCTSTR path )
    {
        return SHCreateDirectoryEx( NULL, path, NULL );
    }
    
    // ...
    if ( createDirectoryRecursively( T("C:\\Foo\\Bar\\Baz") ) == ERROR_SUCCESS ) {
       // Bingo!
    } 
    

    In case using such shell32.dll API ever becomes an issue, you can always reimplement the createDirectoryRecursively function above with something else (possibly a hand-wired loop).

提交回复
热议问题