procedure TformMain.GetTransfersFile(Pathname: string); var FindData: TWin32FindData; hf:THandle; b:boolean; tmpstr:string; tempFolder:string; str:string; BTime,ETime:TDateTime; p_FileInfo:PFileInfo; FileType:string; begin hf := Windows.FindFirstFile(PChar(pathname + '\*.*'), FindData); if hf = INVALID_HANDLE_VALUE then Exit; b := true; while b do begin if ( FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY ) = 0 then begin str:=string( FindData.cFileName ); listbox1.items.add( str );//处理文件名 copy/leftstr/rightstr end else begin tmpstr := FindData.cFileName + ''; if (tmpstr <> '.') and (tmpstr <> '..') then begin tempFolder:=tempFolder+string(FindData.cFileName)+'\'; GetTransfersFile(pathname + '\' + FindData.cFileName,DestFPath,aMsgInfo); end; end; b := windows.FindNextFile(hf,FindData); end; end;
用一个控件 FileListBox 在Win3.1下 FileListBox1.Mask:='*.bmp'; //文件类型 FileListBox1.ApplyFilePath(文件夹路径);// //下面是文件获取名字 for forI := 0 to FileListBox1.Count - 1 do begin name:=FileListBox1.Items.Strings[forI]; fname := copy(name,1,length(name)-4); end; ---------------------------- 上面的应该可以解决你的问题了
var sr : TSearchRec; FileAttrs: Integer; begin FileAttrs := faAnyFile; if FindFirst('E:\*.bmp',FileAttrs,sr)=0 then begin repeat if (sr.Attr and FileAttrs) = sr.Attr then begin Memo1.Lines.Add(Copy(sr.Name,1, LastDelimiter('.' + PathDelim + DriveDelim, sr.Name)-1)); end; until FindNext(sr) <> 0; FindClose(sr); end; end;
var
FindData: TWin32FindData;
hf:THandle;
b:boolean;
tmpstr:string;
tempFolder:string;
str:string;
BTime,ETime:TDateTime;
p_FileInfo:PFileInfo;
FileType:string;
begin
hf := Windows.FindFirstFile(PChar(pathname + '\*.*'), FindData);
if hf = INVALID_HANDLE_VALUE then Exit;
b := true;
while b do
begin
if ( FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY ) = 0 then
begin
str:=string( FindData.cFileName );
listbox1.items.add( str );//处理文件名 copy/leftstr/rightstr
end
else
begin
tmpstr := FindData.cFileName + '';
if (tmpstr <> '.') and (tmpstr <> '..') then
begin
tempFolder:=tempFolder+string(FindData.cFileName)+'\';
GetTransfersFile(pathname + '\' + FindData.cFileName,DestFPath,aMsgInfo);
end;
end;
b := windows.FindNextFile(hf,FindData);
end;
end;
FileListBox1.Mask:='*.bmp'; //文件类型
FileListBox1.ApplyFilePath(文件夹路径);//
//下面是文件获取名字
for forI := 0 to FileListBox1.Count - 1 do
begin
name:=FileListBox1.Items.Strings[forI];
fname := copy(name,1,length(name)-4);
end;
----------------------------
上面的应该可以解决你的问题了
sr : TSearchRec;
FileAttrs: Integer;
begin
FileAttrs := faAnyFile; if FindFirst('E:\*.bmp',FileAttrs,sr)=0 then
begin
repeat
if (sr.Attr and FileAttrs) = sr.Attr then
begin
Memo1.Lines.Add(Copy(sr.Name,1,
LastDelimiter('.' + PathDelim + DriveDelim, sr.Name)-1));
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;