搜索指定类型的文本文件并转换为unicode
2010-01-20 10:15
204 查看
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
- 运用pb将unicode文本文件转换为ANSI文本文件
- Ansi、Unicode、UTF8字符串之间的转换和写入文本文件
- Unicode的一些类型转换问题
- 导入文本文件时如何指定字段类型
- MFC Unicode字符集下 CString类型转换为char*类型
- 在一个10M的文本文件中搜索指定字符串
- unicode下各种类型转换,CString,string,char*,int,char[]
- Ansi、Unicode、UTF8字符串之间的转换和写入文本文件
- 无法在 unicode 和非 unicode 字符串数据类型之间转换。
- JSON类型数据转换为对象,并排除指定的属性.JAVA将购物车数据写入到cookie中
- CString类型转换,字符串操作和UNICODE、ANSI字符集
- 在unicode环境下将CString类型转换成char
- 一些小工具方法,能将容器转换成指定的数组类型有使用泛型
- python知识:json格式文本;异常处理;字符串处理;unicode类型和str类型转换
- 来自数据源的 String 类型的给定值不能转换为指定目标列的类型 nvarchar。
- C# 将一个对象转换为指定类型
- Unicode的一些类型转换问题
- Ansi、Unicode、UTF8等编码字符串之间的转换和写入文本文件(学习中……)
- 如何实现@ResponseBody,把Json字符串转换为指定类型