引数に短いファイルのフルパス名(8.3形式)を入れて以下の関数を呼び出すと、長いファイルのフルパス名を返します。また、与えられたファイルが存在しない場合は、""を返します。
| string GetLongFullPathName(const string& strShortPath) { string strLongPath; int nPos = SJIS_StrChrSearchLast(strShortPath.c_str(), '\\'); if(nPos == -1){ strLongPath = strShortPath; }else{ // 親ディレクトリ名を取得 string strPath = strShortPath.substr(0, nPos); strLongPath = GetLongFullPathName(strPath); // ファイル名を取得 HANDLE hFindFile; WIN32_FIND_DATA sFindData; hFindFile = ::FindFirstFile(strShortPath.c_str(), &sFindData); FindClose(hFindFile); if(hFindFile == INVALID_HANDLE_VALUE) return ""; // 親ディレクトリ名にファイル名を追加 strLongPath += '\\'; strLongPath += sFindData.cFileName; } return strLongPath; } |
関数SJIS_StrChrSearchLastについては、こちらを参照してください。