Home > Back-end >  Everyone a great god, and I look at the code is how to return a responsibility, not to be able to re
Everyone a great god, and I look at the code is how to return a responsibility, not to be able to re

Time:09-16

 
The function TForm1. GetALLFileOfCount (fDirName: string) : Integer;
Var
HFindFile: Cardinal;
TFile, ListName: string;
SCurDir: string [255];
FindFileData: WIN32_FIND_DATA;
The begin
SCurDir:=GetCurrentDir;
The ChDir (fDirname);
HFindFile:=FindFirstFile (' *. * 'FindFileData);
If fDirName [Length (fDirName)] <> '\' then
FDirName:=fDirName + '\';

If hFindFile & lt;> INVALID_HANDLE_VALUE then
The begin
Repeat
The begin
TFile:=FindFileData. CFileName;
If (TFile=') or (TFile='.. ') then
The Continue;
If FindFileData. DwFileAttributes=FILE_ATTRIBUTE_DIRECTORY then
The begin
If fDirName [Length (fDirName)] <> '\' then
+ TFile GetALLFileOfCount (fDirName + '\')
The else
GetALLFileOfCount (fDirName + TFile);
End
The else
FCount:=fCount + 1;
ListName:=fDirName + TFile;
Lst1. Items. The Add (ListName + IntToStr (fCount));
end;
Until FindNextFile (hFindFile, FindFileData)=False;
End
The else
The begin
The ChDir (sCurDir);
The CloseHandle (hFindFile);
exit;
end;
Result:=fCount;
end;

Procedure TForm1. Btn1Click (Sender: TObject);
Var
I: Integer;
The begin
I:=GetALLFileOfCount (edt1. Text);
ShowMessage (IntToStr (I));
end;




look at the picture I sent you a screenshot

Why path also showed out, and at the back of the digital since no + 1, this is how come of, don't understand, is this lst1 directory is not detected Items. The Add (ListName + IntToStr (fCount) code execution, or said I not rigorous code?? Hope the great god directions, thank you






CodePudding user response:

1, this is done by recursively, retrieve all the filename in the specified directory,
2, your arrows directory name is specified, only in the program in the directory, fCount + 1, so it shows or a line on the fCount value,
3, ListName=fDirName + TFile is the path and file name of two parts, added to the List, natural, path to the directory containing the file name,

CodePudding user response:

 function TForm1. GetALLFileOfCount (fDirName: string) : Integer; 
Var
HFindFile: Cardinal;
TFile ListName, Path: string;
SCurDir: string [255];
FindFileData: WIN32_FIND_DATA;
The begin
SCurDir:=GetCurrentDir;
The ChDir (fDirname);
HFindFile:=FindFirstFile (' *. * 'FindFileData);
If fDirName [Length (fDirName)] <> '\' then
FDirName:=fDirName + '\';
If hFindFile & lt;> INVALID_HANDLE_VALUE then
The begin
Repeat
TFile:=FindFileData. CFileName;
If (TFile=') or (TFile='.. ')
Then Continue.
If FindFileData. DwFileAttributes=FILE_ATTRIBUTE_DIRECTORY then
The begin
If fDirName [Length (fDirName)] <> '\'
Then the Path:=fDirName + '\' + TFile
The else Path:=fDirName + TFile;
GetALLFileOfCount (Path)
End
The else fCount:=fCount + 1;
If FindFileData. DwFileAttributes<> FILE_ATTRIBUTE_DIRECTORY then
The begin
ListName:=fDirName + TFile;
ListBox1. Items. The Add (ListName + "+ IntToStr (fCount));
end;
Until FindNextFile (hFindFile, FindFileData)=False;
End
The else begin
The ChDir (sCurDir);
The CloseHandle (hFindFile);
exit;
end;
Result:=fCount;
end;

This change, and display all file, directory, and add the serial number
  • Related