델파이 컴파일러를 사용 합니다
파스칼 언어.
폴더내의 모든 함수를 가져옵니다.
짧은 코드이며, 간단히 수정하여 다른 형태의 함수로 사용이 편리합니다.
path = 경로\폴더이름

ListBox1.Items <-- TStrings
< 사용 예쩨 코드 >
var sl: TStringList;
begin
  sl :=TStringList.Create;
  GetFileListAll(PWideChar(WideString(ExtractFileDir(Application.ExeName))),sl);
  ShowMessage( sl.Strings[0] );
  sl.SaveToFile('test.txt');
  sl.Free;
end;

procedure GetFileListAll(path:WideString;ListAdd:TStrings);
const
  period: WideString='.'; 

  asterisk: WideString='*';
  BackSlash: WideString='\';
var
  SrhRec:TSearchRec;
begin
  if path[Length(path)]<>backSlash[1] then path:=path+backSlash;
  FindFirst(path+asterisk,faAnyFile,SrhRec);
  repeat
    if(SrhRec.Name<>period)and(SrhRec.Name<>period+period)then begin
      if((SrhRec.Attr and faDirectory)>0)then begin
        GetFileListAll(path+SrhRec.Name,ListAdd);
      end else begin
        ListAdd.Add(path+SrhRec.Name);
      end;
    end;
  until(FindNext(SrhRec)<>0);
  FindClose(SrhRec);
end;

ValueFromIndex 사용시 Add 대신할 코드.
        if ListAdd.ClassType=TStringList then begin
          ListAdd.Add(PChar(nil));
          ListAdd.ValueFromIndex[ListAdd.Count-1]:=(path+SrhRec.Name);
        end else ListAdd.Add(path+SrhRec.Name);

2010-12-18 : 빠진 부분이 있어 수정을 완료 해두었습니다.
2011-02-15 : 유니코드 문자열 처리 부분 수정, 사용 예제코드 첨가.
Posted by Nightly Luna
,
® © Tanny Tales
/ rss