300分:将我的电脑中所有*.htm改为*.html,挑战高手!

ss 2002-09-05 06:26:53
我的可用分有6000,请各位放心!

条件:不知道电脑中的硬盘分区,将软驱和光驱除外!

要求速度要快,效率要高,谢谢!
...全文
52 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
cngst 2002-09-06
  • 打赏
  • 举报
回复
修改上一贴:dir/b/s c:\*.htm>c:\filelist.txt
cngst 2002-09-06
  • 打赏
  • 举报
回复
获取硬盘分区列表很简单,可以设置一下循环获取从c到z盘的驱动器类型。

搜索文件用findfirst、findnext

搜索文件列表还有一种更简单的方法,比如搜索所有c盘中的扩展名为.htm的文件并将搜索结果存到C:\filelist.txt中

dir/b/s c:\>c:\filelist.txt
tobbychen 2002-09-06
  • 打赏
  • 举报
回复
up
9igogo 2002-09-06
  • 打赏
  • 举报
回复
up了
iivv 2002-09-06
  • 打赏
  • 举报
回复
原理不难,实现麻烦
ltf_ty 2002-09-06
  • 打赏
  • 举报
回复
我只试过FindFirst这种笨方法!!!
帮你Up一下!!!
longlongge 2002-09-06
  • 打赏
  • 举报
回复
关注……
qimangxing 2002-09-06
  • 打赏
  • 举报
回复
关注!!
up一下。。。
smhpnuaa 2002-09-06
  • 打赏
  • 举报
回复
上面用的是Rich_Zhou(傻乎乎的同舟)的代码,

我已经测试通过,不过建议用多线程,因为这个过程实在是太慢,我的赛阳566、256兆内存、20G硬盘、Win2000几度处于死机状态,硬盘框转不停约5分钟才找到50多个文件。
smhpnuaa 2002-09-06
  • 打赏
  • 举报
回复
unit UnitSearch;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
procedure GetDiskInfo;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
//------------------------------------------------------------------------------
//查找目录下所有文件
function ListAllFiles(const FilePath: string; var FileList:TStringList): Integer;
var
SearchRec: TSearchRec;
ReValue: Integer;
CurrentFilePath: string;
function fcCheckDirectoryFormat(const FilePath:string):string;
begin
Result:=FilePath;
if FilePath[Length(FilePath)]<>'\' then Result:=FilePath+'\';
end;
begin
CurrentFilePath := fcCheckDirectoryFormat(FilePath);
ReValue := FindFirst(CurrentFilePath + '*.*', faAnyFile, SearchRec);
while ReValue = 0 do
begin
if ((SearchRec.Attr and faDirectory) = faDirectory) then //文件夹
begin
if not ((SearchRec.Name = '.') or (SearchRec.Name = '..')) then
begin //递归查找下一个目录
ListAllFiles(CurrentFilePath + SearchRec.Name, FileList);
end;
end
else //普通文件夹
begin
if ExtractFileExt(UpperCase(SearchRec.Name))='.HTM' then
begin
FileList.Add(CurrentFilePath + SearchRec.Name);
end;
end;
ReValue := FindNext(SearchRec);
end;
result := FileList.Count;
end;

//------------------------------------------------------------------------------
//得到有效的硬盘分区
procedure TForm1.GetDiskInfo;
var
i:Integer;
vstring:string;
DTYPE:Integer;
lst:TStringList;
begin
lst:=TStringList.Create;
try
Application.ProcessMessages;
For i:=65 to 90 do
begin
vString:=Chr(i)+':\';
DTYPE:=GetDriveType(PChar(vString));
if DType=DRIVE_FIXED then ListAllFiles(vString,lst);
end;
ListBox1.Items.Assign(lst);
finally
lst.Free;
end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
GetDiskInfo;
end;
smhpnuaa 2002-09-06
  • 打赏
  • 举报
回复
findfirst and firstnext
rename
daniel007 2002-09-05
  • 打赏
  • 举报
回复
关注
wjlsmail 2002-09-05
  • 打赏
  • 举报
回复
文件操作中的几个方法,用 Rich_Zhou(傻乎乎的同舟) 友的,可以
csdndelphi 2002-09-05
  • 打赏
  • 举报
回复
var AvailableDrives :dword;
AvailableDrives := GetLogicalDrives;
for i:= 0 to 25 do
if GetBit(AvailableDrives,i+1)=1 then//如果驱动器存在
begin
DrivePath:=Char(Ord('A')+i)+':\';
if GetDriveType(pchar(DrivePath)) = DRIVE_FIXED then
begin
//硬盘
end;
end;
bcb_fans 2002-09-05
  • 打赏
  • 举报
回复
没有什么难度,唯一需要的是耐心........可惜我不是很有耐心。
csdndelphi 2002-09-05
  • 打赏
  • 举报
回复
搜索并修改保存到文件
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
f:textfile;
searchrec:tsearchrec;
begin
AssignFile(F, 'c:\test.txt');
Rewrite(F);
FindFirst('c:\*.htm', faAnyFile, SearchRec);
Label1.Caption := SearchRec.Name + ' is ' +
IntToStr(SearchRec.Size) + ' bytes in size';
while FindNext(SearchRec) = 0 do begin
Label1.Caption := SearchRec.Name + ' is ' +
IntToStr(SearchRec.Size) + ' bytes in size';
s:=string(Searchrec.Name)+'l';//改名
append(F);
writeln(F,s);//保存文件名
end;
FindClose(SearchRec);
PostQuitMessage(0);
FindClose(SearchRec);
end;
Rich_Zhou 2002-09-05
  • 打赏
  • 举报
回复
3、改变后缀名
RenameFile(FileName, ChangeFileExt(FileName,'.html');
Rich_Zhou 2002-09-05
  • 打赏
  • 举报
回复
2、扫描文件
function ListAllFiles(const MetterPath, FilePath: string; var FileList:
TStringList): Integer;
var
SearchRec: TSearchRec;
ReValue: Integer;
CurrentMetterPath: string;
CurrentFilePath: string;
FileExt: string;
FileCaption: string;
begin
CurrentFilePath := fcCheckDirectoryFormat(FilePath);
CurrentMetterPath := fcCheckDirectoryFormat(MetterPath);
ReValue := FindFirst(CurrentFilePath + '*.*', faAnyFile, SearchRec);
while ReValue = 0 do
begin
if ((SearchRec.Attr and faDirectory) = faDirectory) then
begin
if not ((SearchRec.Name = '.') or (SearchRec.Name = '..')) then
begin
ListAllFiles(CurrentMetterPath + SearchRec.Name,
CurrentFilePath + SearchRec.Name, FileList);
end;
end
else //普通文件夹
begin
if Pos('.htm', UpperCase(SearchRec.Name)) > 0 then
begin
FileCaption := fcGetFileCaption(SearchRec.Name, False);
FileList.Add(CurrentMetterPath + '/' +
FileCaption + '/' + CurrentFilePath + SearchRec.Name);
end;
end;
ReValue := FindNext(SearchRec);
end;
result := FileList.Count;
end;
Rich_Zhou 2002-09-05
  • 打赏
  • 举报
回复
1、扫描硬盘分区
var
i:Integer;
vstring:string;
DTYPE:Integer;
begin
For i:=65 to 90 do
begin
vString:=Chr(i)+':\'
DTYPE:=GetDriveType(PChar(vString));
if DType=DRIVE_FIXED then
showmessage('是有效的硬盘分区')
end;
end;
《待续》
erickleung 2002-09-05
  • 打赏
  • 举报
回复
假如你是用LINUX的, 只需要1-2个指令便可以了. Windows(即DOS 7)恐怕不是
很方便了.
加载更多回复(7)

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧