VC 根據檔案路徑獲取裝置路徑及裝置名

2021-07-13 21:45:17 字數 696 閱讀 7098

專案中間遇到乙個問題,需要判斷檔案在哪個裝置上,翻了一遍msdn,找到了下面的解決方案。

有人可能會覺得_splitpath就可以了,這是不行的,因為_splitpath不能正確獲取掛載到目錄的裝置。

解決思路方法是getvolumepathname獲取裝置根路徑,然後呼叫getvolumenameforvolumemountpoint獲取裝置的名稱。之所以要獲取裝置的名稱是因為:creatfile的輸入路徑必須是裝置名,對於有碟符的裝置根路徑(如c:),裝置根路徑加上裝置字首就是裝置別名(如\\?\c:),但是對於掛載到資料夾的裝置,裝置根路徑加上裝置字首並不是裝置別名。

示例**如下:

wstring getvolumepathbyfile(lpcwstr path);

if(!getvolumepathnamew(path, volume_path, max_path+1))else

return wstring();    

}wstring getvolumenamebyfile(lpcwstr in_path)

volume_path += l"\\";

wchar volume_name[max_path+1];

if(!getvolumenameforvolumemountpointw(volume_path.c_str(), volume_name, max_path+1))else

}

VC 根據路徑遍歷所有檔案

最近做的乙個專案,需要在vc下遍歷指定路徑的所有檔案,和之前的delphi所採用的方式一樣 遞迴呼叫。直接貼 bool cldscanfiledlg doscan const cstring v strdir wchar t chsubdir max long path wchar t chfile...

Java根據路徑獲取檔案內容

首先,給出乙個string表示資源檔案的標識,如何判斷是網路中的檔案還是本地的檔案?http開頭的可以看成是網路檔案 其餘的可看成本地檔案對於mac和linux系統而言 以 和 開頭的表示絕對路徑 其他的看做是相對路徑 對於windows系統而言,絕對路徑形如c test.text 路徑中包含 看成...

使用VC 獲取檔案路徑,已獲取當前路徑為基礎

cpp view plain copy 今天搞清楚了如果使用c 獲取當前路徑,並且已獲取當前路徑為基礎,測試 如下,如果有注釋錯誤還請看到的高手指正,呵呵 cpp view plain copy include include include using namespace std intmain ...