久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <i id='1GH7S'><tr id='1GH7S'><dt id='1GH7S'><q id='1GH7S'><span id='1GH7S'><b id='1GH7S'><form id='1GH7S'><ins id='1GH7S'></ins><ul id='1GH7S'></ul><sub id='1GH7S'></sub></form><legend id='1GH7S'></legend><bdo id='1GH7S'><pre id='1GH7S'><center id='1GH7S'></center></pre></bdo></b><th id='1GH7S'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1GH7S'><tfoot id='1GH7S'></tfoot><dl id='1GH7S'><fieldset id='1GH7S'></fieldset></dl></div>
      <tfoot id='1GH7S'></tfoot>

      <small id='1GH7S'></small><noframes id='1GH7S'>

      1. <legend id='1GH7S'><style id='1GH7S'><dir id='1GH7S'><q id='1GH7S'></q></dir></style></legend>
        • <bdo id='1GH7S'></bdo><ul id='1GH7S'></ul>

        在 Windows 上獲取實際文件名(帶有正確的大小寫

        Getting actual file name (with proper casing) on Windows(在 Windows 上獲取實際文件名(帶有正確的大小寫))

        <legend id='aOyFu'><style id='aOyFu'><dir id='aOyFu'><q id='aOyFu'></q></dir></style></legend>

        <i id='aOyFu'><tr id='aOyFu'><dt id='aOyFu'><q id='aOyFu'><span id='aOyFu'><b id='aOyFu'><form id='aOyFu'><ins id='aOyFu'></ins><ul id='aOyFu'></ul><sub id='aOyFu'></sub></form><legend id='aOyFu'></legend><bdo id='aOyFu'><pre id='aOyFu'><center id='aOyFu'></center></pre></bdo></b><th id='aOyFu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aOyFu'><tfoot id='aOyFu'></tfoot><dl id='aOyFu'><fieldset id='aOyFu'></fieldset></dl></div>

          <small id='aOyFu'></small><noframes id='aOyFu'>

            <bdo id='aOyFu'></bdo><ul id='aOyFu'></ul>
                  <tbody id='aOyFu'></tbody>
                • <tfoot id='aOyFu'></tfoot>
                  本文介紹了在 Windows 上獲取實際文件名(帶有正確的大小寫)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  Windows 文件系統(tǒng)不區(qū)分大小寫.如何,給定文件/文件夾名稱(例如somefile"),我如何獲得該文件/文件夾的實際名稱(例如,如果資源管理器顯示它,它應(yīng)該返回SomeFile")?

                  Windows file system is case insensitive. How, given a file/folder name (e.g. "somefile"), I get the actual name of that file/folder (e.g. it should return "SomeFile" if Explorer displays it so)?

                  我所知道的一些方法,所有這些方法看起來都很落后:

                  Some ways I know, all of which seem quite backwards:

                  1. 給定完整路徑,搜索路徑上的每個文件夾(通過 FindFirstFile).這給出了每個文件夾的正確大小寫結(jié)果.在最后一步,搜索文件本身.
                  2. 從句柄中獲取文件名(如 MSDN 示例中所示)一>).這需要打開一個文件、創(chuàng)建文件映射、獲取它的名稱、解析設(shè)備名稱等.相當(dāng)復(fù)雜.它不適用于文件夾或零大小文件.

                  我是否遺漏了一些明顯的 WinAPI 調(diào)用?最簡單的,如 GetActualPathName() 或 GetFullPathName() 使用傳入的大小寫返回名稱(例如,如果傳入,則返回程序文件",即使它應(yīng)該是程序文件").

                  Am I missing some obvious WinAPI call? The simplest ones, like GetActualPathName() or GetFullPathName() return the name using casing that was passed in (e.g. returns "program files" if that was passed in, even if it should be "Program Files").

                  我正在尋找本機解決方案(不是 .NET 解決方案).

                  I'm looking for a native solution (not .NET one).

                  推薦答案

                  我在此回答我自己的問題,基于 來自 cspirz 的原始答案.

                  And hereby I answer my own question, based on original answer from cspirz.

                  這是一個給定絕對路徑、相對路徑或網(wǎng)絡(luò)路徑的函數(shù),它將返回大寫/小寫的路徑,就像它在 Windows 上顯示的那樣.如果路徑的某個組件不存在,它將返回從該點傳入的路徑.

                  Here's a function that given absolute, relative or network path, will return the path with upper/lower case as it would be displayed on Windows. If some component of the path does not exist, it will return the passed in path from that point.

                  它非常復(fù)雜,因為它試圖處理網(wǎng)絡(luò)路徑和其他邊緣情況.它對寬字符串進(jìn)行操作并使用 std::wstring.是的,理論上 Unicode TCHAR 可能與 wchar_t 不同;這是讀者的練習(xí):)

                  It is quite involved because it tries to handle network paths and other edge cases. It operates on wide character strings and uses std::wstring. Yes, in theory Unicode TCHAR could be not the same as wchar_t; that is an exercise for the reader :)

                  std::wstring GetActualPathName( const wchar_t* path )
                  {
                      // This is quite involved, but the meat is SHGetFileInfo
                  
                      const wchar_t kSeparator = L'\';
                  
                      // copy input string because we'll be temporary modifying it in place
                      size_t length = wcslen(path);
                      wchar_t buffer[MAX_PATH];
                      memcpy( buffer, path, (length+1) * sizeof(path[0]) );
                  
                      size_t i = 0;
                  
                      std::wstring result;
                  
                      // for network paths (\servershareRestOfPath), getting the display
                      // name mangles it into unusable form (e.g. "\servershare" turns
                      // into "share on server (server)"). So detect this case and just skip
                      // up to two path components
                      if( length >= 2 && buffer[0] == kSeparator && buffer[1] == kSeparator )
                      {
                          int skippedCount = 0;
                          i = 2; // start after '\'
                          while( i < length && skippedCount < 2 )
                          {
                              if( buffer[i] == kSeparator )
                                  ++skippedCount;
                              ++i;
                          }
                  
                          result.append( buffer, i );
                      }
                      // for drive names, just add it uppercased
                      else if( length >= 2 && buffer[1] == L':' )
                      {
                          result += towupper(buffer[0]);
                          result += L':';
                          if( length >= 3 && buffer[2] == kSeparator )
                          {
                              result += kSeparator;
                              i = 3; // start after drive, colon and separator
                          }
                          else
                          {
                              i = 2; // start after drive and colon
                          }
                      }
                  
                      size_t lastComponentStart = i;
                      bool addSeparator = false;
                  
                      while( i < length )
                      {
                          // skip until path separator
                          while( i < length && buffer[i] != kSeparator )
                              ++i;
                  
                          if( addSeparator )
                              result += kSeparator;
                  
                          // if we found path separator, get real filename of this
                          // last path name component
                          bool foundSeparator = (i < length);
                          buffer[i] = 0;
                          SHFILEINFOW info;
                  
                          // nuke the path separator so that we get real name of current path component
                          info.szDisplayName[0] = 0;
                          if( SHGetFileInfoW( buffer, 0, &info, sizeof(info), SHGFI_DISPLAYNAME ) )
                          {
                              result += info.szDisplayName;
                          }
                          else
                          {
                              // most likely file does not exist.
                              // So just append original path name component.
                              result.append( buffer + lastComponentStart, i - lastComponentStart );
                          }
                  
                          // restore path separator that we might have nuked before
                          if( foundSeparator )
                              buffer[i] = kSeparator;
                  
                          ++i;
                          lastComponentStart = i;
                          addSeparator = true;
                      }
                  
                      return result;
                  }
                  

                  再次感謝 cspirz 將我指向 SHGetFileInfo.

                  Again, thanks to cspirz for pointing me to SHGetFileInfo.

                  這篇關(guān)于在 Windows 上獲取實際文件名(帶有正確的大小寫)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當(dāng)沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                  When and how should I use exception handling?(我應(yīng)該何時以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構(gòu)造函數(shù)的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區(qū)別)

                  <small id='Be4yh'></small><noframes id='Be4yh'>

                      <bdo id='Be4yh'></bdo><ul id='Be4yh'></ul>
                      <i id='Be4yh'><tr id='Be4yh'><dt id='Be4yh'><q id='Be4yh'><span id='Be4yh'><b id='Be4yh'><form id='Be4yh'><ins id='Be4yh'></ins><ul id='Be4yh'></ul><sub id='Be4yh'></sub></form><legend id='Be4yh'></legend><bdo id='Be4yh'><pre id='Be4yh'><center id='Be4yh'></center></pre></bdo></b><th id='Be4yh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Be4yh'><tfoot id='Be4yh'></tfoot><dl id='Be4yh'><fieldset id='Be4yh'></fieldset></dl></div>

                          <tfoot id='Be4yh'></tfoot>

                              <tbody id='Be4yh'></tbody>
                          • <legend id='Be4yh'><style id='Be4yh'><dir id='Be4yh'><q id='Be4yh'></q></dir></style></legend>
                            主站蜘蛛池模板: 日韩成人av在线 | 欧美日韩视频在线 | 在线一区视频 | 欧美在线视频一区二区 | 日本一道本 | 日韩综合 | 91精品麻豆日日躁夜夜躁 | 亚洲成人精品视频 | 国产精品久久久久久婷婷天堂 | 日韩av在线一区二区 | 色噜噜狠狠色综合中国 | 久热精品视频 | 欧美一区永久视频免费观看 | 国产jizz女人多喷水99 | 成人一区av偷拍 | 精品乱码一区二区 | 一区二区三区四区在线播放 | 亚洲a视频 | 欧美午夜精品久久久久免费视 | 一区二区三区高清不卡 | 国产精品激情 | 国产美女在线观看 | 91麻豆精品一区二区三区 | 国产精品日日夜夜 | 精品国产免费一区二区三区五区 | 国产丝袜一区二区三区免费视频 | 亚洲一区二区精品视频 | 天天干精品 | 日韩精品一区二区三区中文字幕 | 久久男人 | 国产精品中文字幕在线播放 | 久草在线在线精品观看 | jav成人av免费播放 | 国产成人免费一区二区60岁 | 亚洲国产欧美国产综合一区 | 99国产精品99久久久久久粉嫩 | 久久天堂 | 午夜欧美 | 国产精品久久久久久久久免费高清 | 天天综合永久 | av在线一区二区三区 |