zoukankan      html  css  js  c++  java
  • vc 获得文件相对路径

    API函数PathRelativePathTo  
       
      Requirements    
          Version   4.71   and   later   of   Shlwapi.dll  
       
          Header:   Declared   in   shlwapi.h.    
          Import   Library:   shlwapi.lib.

    example:

    #include <windows.h>
    #include <iostream.h>
    #include "Shlwapi.h"

    void main(void)
    {
        char szOut[MAX_PATH] = "";
        char szFrom[ ] = "c:\\a\\b\\path";
        char szTo[ ] = "c:\\a\\x\\y\\file";

        cout  <<  "The relative path is relative from: ";
        cout  <<  szFrom;
        cout  <<  "\n";

        cout  <<  "The relative path is relative to: ";
        cout  <<  szTo;
        cout  <<  "\n";

        PathRelativePathTo(szOut,
                           szFrom,
                           FILE_ATTRIBUTE_DIRECTORY,
                           szTo,
                           FILE_ATTRIBUTE_NORMAL);

        cout  <<  "The relative path is: ";
        cout  <<  szOut;
        cout  <<  "\n";
    }

    OUTPUT:
    ==================
    The relative path is relative from: c:\a\b\path
    The relative path is relative to: c:\a\x\y\file
    The relative path is: ..\..\x\y\file

  • 相关阅读:
    Vmware中“重新安装vmware-tools”按钮置灰如何解决
    如何实现Sublime Text3快速生成html代码
    Windows窗体编程你也行
    .NET基础技术总结
    C#考试题第一波
    C#认证题4(使用标准Windons窗体控件)
    通讯录数据库
    C#认证试题(3)
    c#认证题(2)
    c#认证试题
  • 原文地址:https://www.cnblogs.com/MayGarden/p/1624017.html
Copyright © 2011-2022 走看看