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.
 
 
 





附件列表

 

posted @ 2013-10-22 21:38  XE2011  阅读(253)  评论(0编辑  收藏  举报