2009年4月10日 星期五

win32下 如何轉換相對路徑(relative path)

相對路徑
一般的作法 就是比對兩個路徑
把兩個路徑normalize一下(例如大小寫 或是 是否兩個都是絕對路徑等等)
一段一段比 比到相異點
再組出相對路徑
其實在win32下面有一個很方便的API
可以幫忙組出相對路徑 但是 這個API必須要link shlwapi.lib喔


PathRelativePathTo

This function takes a pair of paths and generates a relative path from one to the other. The paths do not have to be fully-qualified, but they must have a common prefix, or the function will fail and return FALSE.


Sample codes:

沒有留言:

張貼留言