取得某路徑中的所有資料夾 |
答題得分者是:pceyes
|
ivankuo
中階會員 發表:132 回覆:272 積分:95 註冊:2002-11-21 發送簡訊給我 |
請教各位前輩
小弟想要將 A電腦中的C:\Program files\picture\A\ 資料夾內的所有檔案 copy 到 B電腦中的C:\Program files\picture\A\ , 在C:\Program files\picture\ 中可能會有A,B,C,D.....Z 很多個資料夾, 我最終的目的是要將兩個資料夾同步,不管是從A,B那一台電腦產生的檔案,兩邊的資料都得一樣, 於是我用了TDirectoryListBox 和 TFileListBox 兩個元件來處理,但是發現TDirectoryListBox 的items 中, 會有 C:\ ; Program files ; picture ; A ; B ; C ; D ;....D 多個item 但是我想要的只有 picture 底下的資料夾list , 不需要前面 C:\ ; Program files ; picture ; 不知道如何過濾, or 各位前輩有更好的方法可以處理??
------
ivankuo |
RootKit
資深會員 發表:16 回覆:358 積分:419 註冊:2008-01-02 發送簡訊給我 |
|
pceyes
尊榮會員 發表:70 回覆:657 積分:1140 註冊:2003-03-13 發送簡訊給我 |
你應該講的是,在directorylistbox中顯示如c:, Program files, A, B, C等目錄,只要顯示或抓取picture以下之目錄吧,隨手寫一個,希望有更厲害的人士可以提另一作法。
[code delphi] procedure TForm1.Button1Click(Sender: TObject); var i ,j: integer; begin DirectoryListBox1.Directory := edit1.Text; j := DirectoryListBox1.ItemIndex; // picture 的所在位置 for i := 0 to DirectoryListBox1.Items.Count-1 do begin if i > j then begin // 只抓取picture以下的目錄 listbox1.Items.Add(DirectoryListBox1.Items[i]); end; end; end; [/code]
------
努力會更接近成功 |
ivankuo
中階會員 發表:132 回覆:272 積分:95 註冊:2002-11-21 發送簡訊給我 |
|
RootKit
資深會員 發表:16 回覆:358 積分:419 註冊:2008-01-02 發送簡訊給我 |
[code delphi] Function GetDirList(Const DirPath:string;Dirs:TStrings;Const SubDirectories : Boolean = True):Integer; var S : String; Procedure GetDirectoryList(SubPath:string); var SRec : TSearchRec; OK : integer; sPath : String; begin sPath := DirPath SubPath; OK := FindFirst(sPath '*.*',faAnyFile,SRec); while OK = 0 do begin if (SRec.Name<>'.') and (SRec.Name<>'..') then if (SRec.Attr and faDirectory) = faDirectory then begin sPath := Slash(SubPath SRec.Name); Dirs.Add(sPath); if SubDirectories then GetDirectoryList(sPath); end; OK := FindNext(SRec); end; SysUtils.FindClose(SRec); end; begin Result := 0; S := Slash(DirPath); if Not DirectoryExists(S) then Exit; GetDirectoryList(''); Result := Dirs.Count; end; [/code] |
ivankuo
中階會員 發表:132 回覆:272 積分:95 註冊:2002-11-21 發送簡訊給我 |
===================引 用 pceyes 文 章=================== 你應該講的是,在directorylistbox中顯示如c:, Program files, A, B, C等目錄,只要顯示或抓取picture以下之目錄吧,隨手寫一個,希望有更厲害的人士可以提另一作法。 [code delphi] procedure TForm1.Button1Click(Sender: TObject); var i ,j: integer; begin DirectoryListBox1.Directory := edit1.Text; j := DirectoryListBox1.ItemIndex; // picture 的所在位置 for i := 0 to DirectoryListBox1.Items.Count-1 do begin if i > j then begin // 只抓取picture以下的目錄 listbox1.Items.Add(DirectoryListBox1.Items[i]); end; end; end; [/code] 這個方法簡單的就達到我要的了~~~真是感激不盡 for i := j 1 to DirectoryListBox1.Items.Count-1 do begin 這樣也可以
------
ivankuo |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |