D7的一个技术问题,请教各位程序员大哥。

NC217 2017-11-05 05:49:02
function MakeFileList(Path,FileExt:string):TStringList ;
var
E1:integer;
sch:TSearchrec;
asch:string;
begin
E1:=0;
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;
showmessage(sch.name); //显示每个文件夹里的文件名
renamefile(sch.name,concat(IntToStr(E1),'.ern') ); //改名字和后缀名
showmessage(sch.name);//不能正常显示修改后的名字
INC(E1); //文件名计数变量
until FindNext(sch) <> 0;
SysUtils.FindClose(sch);
end;
end;

中文标识的地方我没办法正常运行呀,我应该怎么写这段代码呢?
...全文
433 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
NewComer2017 2017-11-06
  • 打赏
  • 举报
回复
function searchfile(path:string):TStringList; var SearchRec:TSearchRec; found:integer; list:TStringList; begin list:=TStringList.Create; found:=FindFirst(path+'\*.*',faAnyFile,SearchRec); while found=0 do begin if (SearchRec.Name<>'.') and (SearchRec.Name<>'..') and (SearchRec.Attr<>faDirectory) and (SearchRec.Name<>'Thumbs.db') then List.Add(SearchRec.Name); found:=FindNext(SearchRec); end; FindClose(SearchRec); form1.Memo1.Lines.AddStrings(list); end;
lyhoo163 2017-11-05
  • 打赏
  • 举报
回复
  Try
    renamefile(sch.name,concat(IntToStr(E1),'.elky') ); 
    sleep(200);                      // 值要测试  
    INC(E1);
  except
    on e:Exception do
    begin
      ShowMessage(e.Message);
    end;
  end;
这样,试试。
lyhoo163 2017-11-05
  • 打赏
  • 举报
回复
对于磁盘文件的操作,往往有时间差,命令发出后,磁盘的操作经过一段的时间后,才能成功。因此,你的操作就出错了。 两点建议: 1、加入Try组合语句,保证更名出错后,代码能自动退出此操作,并显示出错代码。 2、在磁盘文件操作命令后,加入等待时间差,比如:sleep语句。

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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