ExtractFilePath - C++ Builder

c++
649
2023/10/16 7:04:34
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

ExtractFilePath is a function in C++ Builder that is used to extract the directory path from a given file path.

Syntax:

AnsiString ExtractFilePath(const AnsiString& path);

Parameters:

  • path: The input file path from which the directory path needs to be extracted.

Return Value:

  • The directory path extracted from the input file path.

Example:

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <System.IOUtils.hpp>
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString filePath = "C:\\Program Files\\MyApp\\data\\file.txt";
AnsiString directoryPath = ExtractFilePath(filePath);
ShowMessage(directoryPath);
}

In the above example, the ExtractFilePath function is used to extract the directory path “C:\Program Files\MyApp\data\” from the file path “C:\Program Files\MyApp\data\file.txt”. The extracted directory path is then displayed using the ShowMessage function.

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: c++如何用指针输出二维数组