ExtractNewFolderPath

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  HtmlFileName: string; // "D:C++Builder学习大全中文版index.htm"
  _filesFolder: string; // "D:C++Builder学习大全中文版"
  _filesFolderName: string; // "index_files"
  _filesFolderPath: string; // "D:C++Builder学习大全中文版index_files"
begin
  HtmlFileName := 'D:C++Builder学习大全中文版index.htm';
  _filesFolder := ExtractFilePath(HtmlFileName);
  _filesFolderName := ChangeFileExt(ExtractFileName(HtmlFileName), '') +
    '_files'; // INDEX_files
  _filesFolderPath := _filesFolder + _filesFolderName;
  Memo1.lines.Add(_filesFolderPath);
end;

{
  // "D:C++Builder学习大全中文版index.htm"
  // "D:C++Builder学习大全中文版"
  // "index_files"
  // "D:C++Builder学习大全中文版index_files"
  Caption:=ExtractNewFolderPath('D:C++Builder学习大全中文版index.htm','_files');
  "D:C++Builder学习大全中文版index_files"
}

function ExtractNewFolderPath(FileName: string; NewText: string): string;
var
  _filesFolder: string; // "D:C++Builder学习大全中文版"
  _filesFolderName: string; // "index_files"
  _filesFolderPath: String;
begin
  _filesFolder := ExtractFilePath(FileName);
  _filesFolderName := ChangeFileExt(ExtractFileName(FileName), '') + NewText;
  _filesFolderPath := _filesFolder + _filesFolderName;
  Result := _filesFolderPath;
end;

//  if not DirectoryExists(_filesFolderPath) then
//    CreateDir(_filesFolderPath);

procedure TForm1.Button2Click(Sender: TObject);
var
  s, s1, s2: string;
begin
  s := 'D:C++Builder学习大全中文版index.htm';
  s1:=ExtractNewFolderPath(s,'_files');
  s2 := ExtractNewFolderPath(s, '_AttachMents');
  Memo1.lines.Add(s);
  Memo1.Lines.Add(s1);
  Memo1.lines.Add(s2);
end;

end.
 
 
 





附件列表

原文地址:https://www.cnblogs.com/xe2011/p/3383173.html