我想得到某个文件夹下的所有文件夹的名字,以下是我的代码,但有两个问题:
1只能在2000以上操作系统中能行,在98下就得不到;
2连该目录下的文件名也都加进去了,我只想要文件夹名。
望高手指教!
我的代码如下:
procedure TFSetting.GetAllNames;
var
i:integer;
vSearchRec: TSearchRec;
path:string;
begin
combobox_name.Items.Clear;
 ComboBox_name.Items.Add('Null');
path:=ExtractFilePath(application.ExeName)+'Skins\*.*';
i := FindFirst(path, faDirectory, vSearchRec);
while i = 0 do begin
if (vSearchRec.Name<>'.') and (vSearchRec.Name<> '..') then
begin
ComboBox_name.Items.Add(vSearchRec.Name);
end;
i:= FindNext(vSearchRec);
end;
FindClose(vSearchRec);
end;

解决方案 »

  1.   

    看来这位老兄还没有真正了解那几个函数的用法,再去看看help或搜一下吧
      

  2.   

    获得文件夹:
    function ListDirs(Path: string; List: TStringList): Integer;
    var
      FindData: TWin32FindData;
      FindHandle: THandle;
      FileName: string;
      AddToList: Boolean;
    begin
      Result := 0;
      AddToList := Assigned(List);  if Path[Length(Path)] <> '\' then
        Path := Path + '\';  Path := Path + '*.*';  FindHandle := Windows.FindFirstFile(PChar(Path), FindData);
      while FindHandle <> INVALID_HANDLE_VALUE do
      begin
        FileName := StrPas(FindData.cFileName);
        if (FileName <> '.') and (FileName <> '..') and
          ((FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0) then
        begin
          Inc(Result);
          if AddToList then
            List.Add(FileName);
        end;    if not Windows.FindNextFile(FindHandle, FindData) then
          FindHandle := INVALID_HANDLE_VALUE;
      end;
      Windows.FindClose(FindHandle);
    end;使用:
    var
      s: TStringList;
    begin
      s := TStringList.Create;
      ListDirs('c:\windows\', s);
      ListBox1.Items.AddStrings(s);
      s.Free;
    end;
      

  3.   

    FindFirstFile + FindNextFile
      

  4.   

    FindFirstFile + FindNextFile
    递归
      

  5.   

    to :lianshaohua,hellolongbin 两位不要装得很深沉,你不懂可以选择不说话的
    to:others,感谢各位的热心帮助,问题我已找到,是我测试时犯了个小错误,这段代码完全可以用。谢谢! 结贴!