新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

ExtractFilePath - C++ Builder

发布时间:2023-09-28 07:04:34

ExtractFilePath - C++ Builder

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 
#pragma hdrstop
#include "Unit1.h"
#include 
#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 FilesMyAppdata" from the file path "C:Program FilesMyAppdata ile.txt". The extracted directory path is then displayed using the ShowMessage function.