get directory from file path c++

前端 未结 11 1418
梦如初夏
梦如初夏 2020-12-13 14:45

What is the simplest way to get the directory that a file is in? I\'m using this to find the working directory.

string filename = \"C:\\MyDirectory\\MyFile.b         


        
11条回答
  •  眼角桃花
    2020-12-13 15:13

    As Question is old but I would like to add an answer so that it will helpful for others.
    in Visual c++ you can use CString or char array also

    CString filename = _T("C:\\MyDirectory\\MyFile.bat");  
    PathRemoveFileSpec(filename); 
    

    OUTPUT:

    C:\MyDirectory

    Include Shlwapi.h in your header files.

    MSDN LINK here you can check example.

提交回复
热议问题