Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- PostgreSQL
- SQL
- VB.NET
- 예제
- 데이터베이스
- 셋업
- 설치
- 입문
- 파이어버드
- 소니
- Delphi
- MFC
- 델파이
- Visual Basic
- Visual Studio 2005
- xml
- Firebird
- vb
- MySQL
- 초보
- WIN32 SDK
- SDK
- 파라미터
- 기초
- 인스톨
- dll
- winsock
- 문자열
- 시리얼 통신
- c#
Archives
- Today
- Total
프로그래밍 노트
[델파이] 지정한 폴더에 들어 있는 파일을 표시2 본문
지정한 폴더에 들어있는 파일을 검색해서 TStringList로 반환해주는 함수 예제
서브 폴더 밑의 파일까지도 파일을 까지도 검색하는 함수
// ************************************************************ // 지정한 폴더 밑에 파일을 필터링하여 // 지정한 폴더 밑의 파일 리스트를 얻는 함수 // ************************************************************ procedure GetSearchedFileList(sPath : String; slFileList : TStringList; sWildStr : string; bSchSubFolder : Bool); var sTempPath : String; SchRec : TSearchRec; iSchRec : integer; begin // 뒤에 '\' 붙이기 if sPath[length(sPath)] <> '\' then sPath := sPath + '\'; // 와일드 카드 설정 if (sWildStr = '') or (bSchSubFolder = true) then sTempPath := sPath + '*.*' else sTempPath := sPath + sWildStr; iSchRec := FindFirst(sTempPath, faAnyFile or faDirectory, SchRec); while (iSchRec = 0) do begin // '.', '..' 폴더는 제외 if not ((SchRec.Name = '.') or (SchRec.Name = '..')) then begin // 폴더가 아닌 것 if (SchRec.Attr and faDirectory) = 0 then begin // 와일드카드를 설정하고 서브폴더 밑도 검색할 경우 if (bSchSubFolder = true) and ((sWildStr <> '') or (sWildStr <> '*.*')) then begin // 수동 필터링 : *.확장자만 지원 / '?'는 지원안함 if ExtractFileExt(SchRec.Name) = ExtractFileExt(sWildStr) then slFileList.add(sPath + SchRec.Name); end // 일반적인 경우 : 서브폴더 밑 검색안함 else slFileList.add(sPath + SchRec.Name); end // 폴더인 경우 else begin // 폴더 안에 파일도 검색하는 경우 if bSchSubFolder = true then begin // 파일 검색 함수 : 재귀호출 GetSearchedFileList(sPath + SchRec.Name + '\', slFileList, sWildStr, bSchSubFolder); end; end; end; iSchRec := FindNext(SchRec); end; FindClose(SchRec); end; // ************************************************************ // 지정한 폴더 밑에 파일을 필터링하여 StringList로 반환 // ************************************************************ procedure GetFileList(sPath : String; slFileList : TStringList; sWildCard : string = ''; bSearchSubFolder : Bool = false); begin slFileList.Clear; GetSearchedFileList(sPath, slFileList, sWildCard, bSearchSubFolder); end; procedure TForm2.Button2Click(Sender: TObject); var slFileList : TStringList; begin // TStringList초기화 slFileList := TStringList.Create; GetSearchedFileList('D:\work', slFileList, '*.CSV', true); //GetFileList('D:\work', slFileList); ListBox1.Items := slFileList; end;
Comments