woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

绝对路径转为相对路径

    http://blog.csdn.net/fengrx/article/details/4330946

     

    #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"; 

    #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

posted on 2012-09-05 14:13 肥仔 阅读(3023) 评论(0)  编辑 收藏 引用 所属分类: Windows开发


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理