搜索指定类型的文本文件并转换为unicode

unit UnitMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, StrUtils, ComCtrls; type TForm1 = class(TForm) Memo1: TMemo; ListBox1: TListBox; GroupBox1: TGroupBox; Button1: TButton; EditExt: TEdit; Label1: TLabel; Label2: TLabel; EditDir: TEdit; Button2: TButton; Memo2: TMemo; pbar: TProgressBar; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function MakeFileList(Path,FileExt:string):TStringList ; var sch:TSearchrec; begin Result:=TStringlist.Create; if rightStr(trim(Path), 1) <> '/' then Path := trim(Path) + '/' else Path := trim(Path); if not DirectoryExists(Path) then begin Result.Clear; exit; end; if FindFirst(Path + '*', faAnyfile, sch) = 0 then begin repeat Application.ProcessMessages; if ((sch.Name = '.') or (sch.Name = '..')) then Continue; if DirectoryExists(Path+sch.Name) then begin Result.AddStrings(MakeFileList(Path+sch.Name,FileExt)); end else begin if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then Result.Add(Path+sch.Name); end; until FindNext(sch) <> 0; SysUtils.FindClose(sch); end; end; //搜索符合条件的文本文件 procedure TForm1.Button1Click(Sender: TObject); begin ListBox1.Items:= MakeFileList( EditDir.Text, EditExt.Text); end; //转换为unicode procedure TForm1.Button2Click(Sender: TObject); var i: integer; strunicode: widestring; txtFile: TextFile; //ms:TMemoryStream; begin pbar.Max := ListBox1.Items.Count; for i:=0 to ListBox1.Items.Count - 1 do begin Memo1.Lines.LoadFromFile(ListBox1.Items.Strings[i]); pbar.Position := i; DeleteFile(ListBox1.Items.Strings[i]); strunicode := widestring(Memo1.Text); memo2.Text := strunicode; memo2.Lines.SaveToFile(ListBox1.Items.Strings[i]);; end; pbar.Position := 0; showmessage('ok'); end; end.

 

源码和exe程序已经上传的我的资源。

 

http://hi.csdn.net/link.php?url=http://bq_cui.download.csdn.net

你可能感兴趣的:(搜索指定类型的文本文件并转换为unicode)