Reputation: 367
I try to get the subdirectories of a directorie i have a working script but i only want the subdirectorie name and not the names of the directories before.
Example:
If i enter: "\Program Files (x86)\Embarcadero\RAD Studio\12.0"
Then this is my output now:
"\Program Files (x86)\Embarcadero\RAD Studio\12.0\bin"
"\Program Files (x86)\Embarcadero\RAD Studio\12.0\bin64"
"\Program Files (x86)\Embarcadero\RAD Studio\12.0\binosx32"
...
But i want that my output is:
"bin"
"bin64"
"binosx32"
...
This is the script what i use now:
procedure GetSubDirectories(const directory : string; list : TStrings) ;
var
sr : TSearchRec;
begin
try
if FindFirst(IncludeTrailingPathDelimiter(directory) + '*.*', faDirectory, sr) < 0 then
Exit
else
repeat
if ((sr.Attr and faDirectory <> 0) AND (sr.Name <> '.') AND (sr.Name <> '..')) then
List.Add(IncludeTrailingPathDelimiter(directory) + sr.Name) ;
until FindNext(sr) <> 0;
finally
SysUtils.FindClose(sr) ;
end;
end;
How can i make this script like in my example?
Upvotes: 3
Views: 3462
Reputation: 28728
Replace
List.Add(IncludeTrailingPathDelimiter(directory) + sr.Name)
with
List.Add(sr.Name)
Upvotes: 8