ExpandFileName - C++ Builder

C++ Builder 參考手冊 ? System::Sysutils ? ExpandFileName


把相對路徑轉(zhuǎn)為完整路徑

頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:

System::UnicodeString __fastcall ExpandFileName(const System::UnicodeString FileName);

參數(shù):

  • FileName 文件名/文件夾名,字符串;

返回值:

  • 參數(shù) FileName 字符串前面加上完整的路徑的字符串;
  • ExpandFileName 不檢查文件是否存在,只是按照當(dāng)前路徑擴展為完整路徑;
    ? 可以通過 SetCurrentDir 修改當(dāng)前文件夾位置;
    ? 可以通過 GetCurrentDir 獲取當(dāng)前文件夾位置;
  • 不支持 UNC (Universal Naming Convention) 格式,如果需要 UNC 格式的文件名,需要用 ExpandUNCFileName 函數(shù)。

例子:

#include <System.IOUtils.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    UnicodeString s = Sysutils::ExpandFileName(L"Test.txt");
    Memo1->Lines->Add(s);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    UnicodeString s = Ioutils::TPath::GetDocumentsPath(); // 獲取 "我的文檔" 文件夾位置
    Sysutils::SetCurrentDir(s); // 設(shè)置當(dāng)前路徑為 "我的文檔" 文件夾
    s = Sysutils::ExpandFileName(L"Test.txt"); // 相對路徑轉(zhuǎn)為完整路徑
    Memo1->Lines->Add(s);
}

運行結(jié)果:

點擊 Button1 運行結(jié)果
點擊 Button2 運行結(jié)果

相關(guān):

  • System::Sysutils::ExpandFileName
  • System::Sysutils::ExpandFileNameCase
  • System::Sysutils::ExpandUNCFileName
  • System::Sysutils::GetCurrentDir
  • System::Sysutils::SetCurrentDir
  • System::Sysutils::GetHomePath
  • System::Sysutils::ChangeFileExt
  • System::Sysutils::ChangeFilePath
  • System::Sysutils::ExtractFileDir
  • System::Sysutils::ExtractFileDrive
  • System::Sysutils::ExtractFileExt
  • System::Sysutils::ExtractFileName
  • System::Sysutils::ExtractFilePath
  • System::Sysutils::ExtractRelativePath
  • System::Sysutils::ExtractShortPathName
  • System::Sysutils
  • System::Ioutils::TPath
  • System::Ioutils
  • std::_fullpath, std::_tfullpath, std::_wfullpath
  • std::_makepath, std::_tmakepath, std::_wmakepath
  • std::_splitpath, std::_tsplitpath, std::_wsplitpath
  • <cstdlib>

C++ Builder 參考手冊 ? System::Sysutils ? ExpandFileName

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容