Arsip: coding utk find folder??

 
user image
more 19 years ago

imunk

dear mas2 milis.... langsung aja, gimana sih bikin coding tuk mencari folder yg kita tentukan. aku dah coba tanya sama om google tapi dikasihnya shareware semua, males ah......:) kalo mas2 punya triknya tolong dong help me... thanks before.. maju terus.
user image
more 19 years ago

DelphiExpert

Mencari folder gimana maksud lu Munk? Try using FindFirst, FindNext procedure; Sample: The following example uses an edit control, a button, a string grid, and seven check boxes. The check boxes correspond to the seven possible file attributes. When the button is clicked, the path specified in the edit control is searched for files matching the checked file attributes. The names and sizes of the matching files are inserted into the string grid.
procedure TForm1.Button1Click(Sender: TObject);
var
  sr: TSearchRec;
  FileAttrs: Integer;
begin
  StringGrid1.RowCount := 1;
  if CheckBox1.Checked then
    FileAttrs := faReadOnly
  else FileAttrs := 0;
  if CheckBox2.Checked then
    FileAttrs := FileAttrs + faHidden;
  if CheckBox3.Checked then
    FileAttrs := FileAttrs + faSysFile;
  if CheckBox4.Checked then
    FileAttrs := FileAttrs + faVolumeID;
  if CheckBox5.Checked then
    FileAttrs := FileAttrs + faDirectory;
  if CheckBox6.Checked then
    FileAttrs := FileAttrs + faArchive;
  if CheckBox7.Checked then
    FileAttrs := FileAttrs + faAnyFile;
  with StringGrid1 do
  begin
    RowCount := 0;
    if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then
    begin
      repeat
        if (sr.Attr and FileAttrs) = sr.Attr then
        begin
        RowCount := RowCount + 1;
        Cells[1,RowCount-1] := sr.Name;
        Cells[2,RowCount-1] := IntToStr(sr.Size);
        end;
      until FindNext(sr) <> 0;
      FindClose(sr);
    end;
  end;
end;
So, utk membedakan object dalam pencarian itu Directory ato File bisa dibedakan dari attribut "faDirectory in FileAttrs" OK - Regards, D.E
user image
more 19 years ago

ridwantsm

function BrowseForFolder(var Foldr: string; Title: string): 
Boolean;
var
  BrowseInfo: TBrowseInfo;
  ItemIDList: PItemIDList;
  DisplayName: array of Char;
begin
  Result := False;
  FillChar(BrowseInfo, SizeOf(BrowseInfo),#0);
  with BrowseInfo do begin
    hwndOwner := Application.Handle;
    pszDisplayName := @DisplayName[0];
    lpszTitle := PChar(Title);
    ulFlags := BIF_RETURNONLYFSDIRS;
  end;
  ItemIDList := SHBrowseForFolder(BrowseInfo);
  if Assigned(ItemIDList) then
    if SHGetPathFromIDList(ItemIDList, DisplayName) then begin
      Foldr := DisplayName;
      Result := True;
    end;
end; 
BY RIDWAN SMKN 2 TASIKMALAYA :lol: :lol: :lol:
user image
more 19 years ago

saysansay

Wah krenzzzzzzzzzzzzzzzz Nech Ridwan...Wakakakaaaa.
user image
more 19 years ago

DelphiExpert

:mrgreen: WAKAKAKAKA.... salah tangkep nih gue. maklum pada bocor ni kepala :mrgreen: Yang itu tho maksudnye wakakak
user image
more 19 years ago

kaka-delphi

Wah hebat Ridwan udah jago Delphi sekarang nich :D :D :D . kok ga ngomong2 wan ? Hebat laaaah .... !!! Tetep Semangat !!!
user image
more 19 years ago

imunk

siiiiipppp...... emang delphi-id sumber segala permasalahan deh.....:) thanks buat yang dah ngejawab, moga ilmunya bertambah.... moga pertanyaanku yg ini masih ke baca.....:) kalo tuk mendeteksi daftar semua drive (partisi drive kayak drive C, D dll) yg ada pada HD gimana ya mas...??? moga ini jg bs terjawab, soalnya berhubungan ma yg di atas.....:) thanks before... maju terus.
user image
more 19 years ago

ZeAL

errr...kalo mo cepet pake komponen DriveList (kalo gak salah) ada di tab WIN31... ntar tinggal dibaca isi listnya deh... Kalo hard coding...emmm... gak tauuuuu.... hehehe.. :D
user image
more 19 years ago

DelphiExpert

Wakakak... pake fungsi "SelectDirectory" ni biar kerreeennn... :mrgreen:

uses FileCtrl;
procedure TForm1.Button1Click(Sender: TObject);
var Dir: string;
begin
  if SelectDirectory('Pilih direktory...', '', Dir) then
    ShowMessage('OK, Anda memilih direktory: ' + Dir);
end;
Wakakakakak... browse... browse... browse... (diomongin "mencari folder" kagak nyambung :mrgreen: ) wakakak...
user image
more 19 years ago

doditali

boleh nggak ikutan nimbrung mencari file !!!! saya sampe sekarang masih bingung nihh !!! tapi kalo cari directory dgn pake file mask, aku sich pake koding seperti ini : saya pake komponen form, button, edit, checkbox, listbox, label, dsb liat aja di koding !!!!
utk komponen edit : isikan properti text edit1 = c:\ lalu isikan properti text edit2 = .

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;
type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Button1: TButton;
    CheckBox1: TCheckBox;
    ListBox1: TListBox;
    Label3: TLabel;
    Panel1: TPanel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
  private
    { Private declarations }
    procedure Filecari(const namapath, namafile : string; const dalamDir : boolean);
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R .dfm}
procedure Tform1.Filecari(const namapath, namafile : string; const dalamDir : boolean);
var Rec  : TSearchRec;
    Path : string;
begin
Path := IncludeTrailingBackslash(namapath);
if FindFirst(Path + namafile, faAnyFile - faDirectory, Rec) = 0 then
 try
   repeat
     ListBox1.Items.Add(Path + Rec.Name);
   until FindNext(Rec) <> 0;
 finally
   FindClose(Rec);
 end;
If not dalamDir then Exit;
if FindFirst(Path + ' .', faDirectory, Rec) = 0 then
 try
   repeat
     Filecari(Path + Rec.Name, namafile, True);
   until FindNext(Rec) <> 0;
 finally
   FindClose(Rec);
 end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
 ListBox1.Clear;
  label3.Caption:=Inttostr(ListBox1.Items.Count) + ' file yg ketemu.';
  Filecari(Edit1.Text, Edit2.Text, CheckBox1.State in [cbChecked]);
  label3.Caption:=Inttostr(ListBox1.Items.Count) + ' juml file yg ketemu.';
end;
procedure TForm1.ListBox1DblClick(Sender: TObject);
var SelectedFile : string;
    Rec          : TSearchRec;
begin
SelectedFile := ListBox1.Items.Strings[ListBox1.ItemIndex];
if FindFirst(SelectedFile, faAnyFile, Rec) = 0 then
 begin
    label4.Caption := SelectedFile;
    label9.Caption := Rec.name;
    label10.Caption := Format('%d bytes',[Rec.Size]);
    label11.Caption := DateToStr(FileDateToDateTime(Rec.Time));
    label12.Caption := Rec.FindData.cAlternateFileName;
   FindClose(Rec)
 end;
end;
end.
utk koding search directory :

 private
    { Private declarations }
    procedure Filecari(const namapath, namafile : string; const dalamDir : boolean);
  public
    { Public declarations }

procedure Tform1.Filecari(const namapath, namafile : string; const dalamDir : boolean);
var Rec  : TSearchRec;
    Path : string;
begin
Path := IncludeTrailingBackslash(namapath);
if FindFirst(Path + namafile, faAnyFile - faDirectory, Rec) = 0 then
 try
   repeat
     ListBox1.Items.Add(Path + Rec.Name);
   until FindNext(Rec) <> 0;
 finally
   FindClose(Rec);
 end;
If not dalamDir then Exit;
if FindFirst(Path + ' .*', faDirectory, Rec) = 0 then
 try
   repeat
     Filecari(Path + Rec.Name, namafile, True);
   until FindNext(Rec) <> 0;
 finally
   FindClose(Rec);
 end;
end;
ok, coba aja kalo bisa di compile syukur dech ...
more ...
  • Pages:
  • 1
Share to

AI Forward

🚀 We're thrilled to partner with Alibaba Cloud for "AI Forward - Alibaba Cloud Global Developer Summit 2025" in Jakarta! Join us and explore the future of AI. Register now: https://int.alibabacloud.com/m/1000400772/
#AlibabaCloud #DeveloperSummit #Jakarta #AIFORWARD

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com