傳統的獲取Windows特殊目錄路徑方法是調用SHGetSpecialFolderPath 函數,比如“我的文檔”, “我的音樂”。
Vista/Win7 多了一個“下載”(英文版上是 "Downloads" )目錄, 該目錄是無法用SHGetSpecialFolderPath 獲得的。 需要使用新函數 SHGetKnownFolderPath 。 傳入FOLDERID_Downloads 參數就可以得到該路徑:
SHGetKnownFolderPath(FOLDERID_Downloads, 0, NULL, &szDownloadFolderPath);
MSDN上列出了其他特殊目錄的FOLDERID參數: http://msdn.microsoft.com/en-us/library/dd378457(VS.85).aspx
需要注意的是,SHGetKnownFolderPath 只有在Vista及以後版本纔有, 所以請使用GetProcAddress 來調用 (而不是直接鏈接)。