用字串技巧取檔名和路徑
¶用字串技巧取檔名和路徑
原文連結: https://darkblack01.blogspot.com/2012/08/blog-post_15.html
移植時的最後更新日期: 2012-08-15T17:07:37.028+08:00
CString str;
CString path;
CString FileName;
str = “C:\Program Files\Bonjour\mdnsNSP.dll”  //隨便從硬碟中找一個檔案路徑來試
拆成檔名和路徑:
FileName =  str.Right( str.GetLength() - str.ReverseFind(’\’) - 1);
path =  str.Left( str.ReverseFind(’\’));
程式結果:
FileName = mdnsNSP.dll
path = C:\Program Files\Bonjour
合拼起來:
CString filepath;
filepath.Format("%s\%s", path, FileName);
程式結果:
filepath = C:\Program Files\Bonjour\mdnsNSP.dll
                發表於 
                
            
            
                
                    tags:
                    
  
  { WIN32 API/MFC }