SysUtilsStrRScan (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example uses an Open dialog box and a button on a form. When the button is clicked, the user is prompted for a file name. Then the file name, minus its path, is displayed in a message box. Note: This technique does not work with multibyte character sets (MBCS). To be more general, use ExtractFileName.

Code

char *__fastcall GetFileName(char *pszFilePath)
{
  char *pszFileName = StrRScan(pszFilePath, '\\');
  if (!pszFileName)
    pszFileName = pszFilePath;
  else
	pszFileName++;
  return pszFileName;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (OpenDialog1->Execute())
  {
	char *name = GetFileName(OpenDialog1->FileName.t_str());
	Application->MessageBox(
	  WideString(name).c_bstr(),
	  L"File Name",
	  MB_OK);
  }
}

Uses