怎样得到某个目录下所有的文件名?

foxe 2003-02-24 09:47:34
我想实现:得到一个目录下所有文件名,每COPY一个在LISTBOX中显示一个文件名,请问怎么样可以实现?谢谢,在线等!
...全文
43 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xdf_hubei 2003-02-24
  • 打赏
  • 举报
回复
function DanverCopy(fFROM, fTO: string; Method: integer): boolean;
var
FData: TShFileOpStruct;
begin
Fdata.pFrom := PChar(fFrom + #0#0); //设立数据源路径和文件、目录名,支持(?, *通配符)
fdata.pTo := PChar(fTo + #0#0); //设立目标路径
if Method = 1 then
fdata.wFunc := FO_COPY //设立操作方式
else if Method = 2 then //FO_COPY 拷贝操作 相当于 XCOPY
fdata.wFunc := FO_MOVE //FO_MOVE 移动操作 相当于 MOVE
else if Method = 3 then //FO_DELETE 删除操作 相当于 DELTREE,第二个参数被忽略
fdata.wFunc := FO_DELETE
else if Method = 4 then
fdata.wFunc := FO_RENAME //改名
else
begin
ShowMessage('操作参数不可识别');
result := false;
exit;
end;
FData.Wnd := 0;
fData.lpszProgressTitle := 'Wait'; //设立提示窗标题
fData.fFlags := FOF_NOCONFIRMMKDIR or FOF_NOCONFIRMATION; //设定操作选项
result := ShFileOperation(FData) = 0;
end;

上面的代码用于COPY文件和其他功能
foxe 2003-02-24
  • 打赏
  • 举报
回复
再多问一个,COPY文件用什么函数好?
sysu 2003-02-24
  • 打赏
  • 举报
回复
FindFirst、FindNext,按F1看帮助,里面有例子。
xdf_hubei 2003-02-24
  • 打赏
  • 举报
回复
function GetFileList(path:string;Attr:integer;FileList:TStringList):boolean;
var
SearchRec: TSearchRec;
i:integer;
begin
i:=FindFirst(path, attr, SearchRec);
if i <> 0 then
begin
result := false;
exit;
end;

while i = 0 do
begin
FileList.Add(SearchRec.Name);
i:=FindNext(SearchRec);
end;
FindClose(SearchRec);
result := true;
end;

使用范例:
var
FileList:Tstringlist;
begin
filelist := Tstringlist.Create;
getfilelist(ExtractFilePath(Application.ExeName)+'*.*',faAnyFile,filelist
filelist.free;

end;

1,184

社区成员

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

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