How do I recursively create a folder in Win32?

前端 未结 14 1312
孤城傲影
孤城傲影 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:32

    UnicodeString path = "C:\\Test\\Test\\Test\\";
    TStringList *list = new TStringList();
    
    try
    {
        list->Delimiter = '\\';
        list->StrictDelimiter = true;
        list->DelimitedText = path;
        path = list->Strings[0]; \\drive letter
        for(int i = 1; i < list->Count - 1; i++)
        {
            try
            {
                path += "\\" + list->Strings[i];
                CreateDirectory(path.w_str(), NULL);
            }
            catch(...) { }
        }
    }
    catch(...) { }
    delete list;
    

提交回复
热议问题