zoukankan      html  css  js  c++  java
  • 相对路径转绝对路径(Win)

    绝对路径转相对路径可以使用:PathRelativePathTo
    相对路径转绝对路径好像没有现成的。

    可以考虑 GetCurrentDirectory  GetModuleFileName  PathStripPath 等。

    问题描述:需要根据Path来判断它属于那个分区。但是不支持相对路径。
    目标:    支持相对路径和绝对路径。
    解决方法:

    char GetDriveName(LPWSTR lpszPath)
    {
        //we assume that the lpszPath passed in is valid, if not, Results Not Guaranteed.
        WCHAR szBuffer[MAX_PATH] = {0};
        
        if(PathIsRelative(lpszPath))
            GetCurrentDirectoryW(MAX_PATH, szBuffer);
        else
            wcscpy_s(szBuffer, MAX_PATH, lpszPath);
    
        return PathGetDriveNumberW(szBuffer)+'A';
    }
    
    void main()
    {
        const int ARRAY_LEN = 20;
        WCHAR szPath[][ARRAY_LEN] = { L".\GotData.mp3", L"D:\WinStuff.zip"};
        int len = sizeof(szPath) / sizeof(szPath[0]);
    
        for(int i = 0; i < len; i++)
        {
            wcout<<L"Path:	"<<szPath[i]<<endl;
            wcout<<L"Drive Name:	"<<GetDriveName(szPath[i])<<endl;
        }
        system("pause");
    }

    测试结果:

    Path:   .GotData.mp3
    Drive Name:     E
    Path:   D:WinStuff.zip
    Drive Name:     D
    请按任意键继续. . .

  • 相关阅读:
    CSS边框
    各大网站注册的用处(个人看法)
    20121011 外边距
    20120921碎碎念
    20121011 CSS一
    20120919碎碎念
    CSS 文本装饰属性
    外边距合并
    EverBox开发笔记1
    “Core Data”中的“dynamic implementation”
  • 原文地址:https://www.cnblogs.com/tupx/p/3484259.html
Copyright © 2011-2022 走看看