C++ Builder 参考手册 ➙ System::Sysutils ➙ ExpandFileName
把相对路径转为完整路径
头文件:#include <System.SysUtils.hpp>
命名空间:System::Sysutils
函数原型:
System::UnicodeString __fastcall ExpandFileName(const System::UnicodeString FileName);
参数:
- FileName 文件名/文件夹名,字符串;
返回值:
- 参数 FileName 字符串前面加上完整的路径的字符串;
- ExpandFileName 不检查文件是否存在,只是按照当前路径扩展为完整路径;
• 可以通过 SetCurrentDir 修改当前文件夹位置;
• 可以通过 GetCurrentDir 获取当前文件夹位置; - 不支持 UNC (Universal Naming Convention) 格式,如果需要 UNC 格式的文件名,需要用 ExpandUNCFileName 函数。
例子:
#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); // 设置当前路径为 "我的文档" 文件夹
s = Sysutils::ExpandFileName(L"Test.txt"); // 相对路径转为完整路径
Memo1->Lines->Add(s);
}
运行结果:
相关:
- 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