本人delphi业余初学爱好者写的,高手就不要看了,怕你们做恶梦^-^
介绍就不用了吧,呵呵
注代码:
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Menus,FileCtrl;
type TForm1 = class(TForm) GroupBox1: TGroupBox; Label1: TLabel; Label2: TLabel; Edit1: TEdit; Edit2: TEdit; Label3: TLabel; Button1: TButton; Button2: TButton; procedure cxButton1Click(Sender: TObject); function RenameFileEx(Dir1,Ext1: String): Boolean; procedure cxButton2Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; Dir1:String; implementation
{$R *.dfm} function TForm1.RenameFileEx(Dir1,Ext1: String): Boolean; var search: TSearchRec; ret: integer; key: string; Bname: string; begin if Dir1[Length(Dir1)] <> '\' then Dir1 := Dir1 + '\';
key := Dir1 + '*.*'; ret := findFirst(key, faanyfile, search); while ret = 0 do begin if ((search.Attr and fadirectory) = faDirectory) then begin if (Search.Name <> '.') and (Search.name <> '..') then RenameFileEx(Dir1 + Search.name,Ext1); end else begin if ((search.attr and fadirectory) <> fadirectory) then begin Bname:=ChangeFileExt(Dir1+search.Name,'.'+Ext1); RenameFile(Dir1+search.Name,Bname); end; end; ret := FindNext(search); end; findClose(search);
result := True; end;
procedure TForm1.cxButton1Click(Sender: TObject); begin SelectDirectory('请选择文件夹','',Dir1); edit2.Text:=Dir1; end; procedure TForm1.cxButton2Click(Sender: TObject); var aa:string; begin try RenameFileEx(Trim(edit2.Text),Trim(edit1.Text)); except ShowMessage('没有输入目标目录!'); end;
end;
procedure TForm1.Button2Click(Sender: TObject); var aa:string; begin try RenameFileEx(Trim(edit2.Text),Trim(edit1.Text)); except ShowMessage('没有输入目标目录!'); end; end;
procedure TForm1.Button1Click(Sender: TObject); begin SelectDirectory('请选择文件夹','',Dir1); edit2.Text:=Dir1; end;
end. |