Arsip: coding utk find folder??

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.

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
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:
more 19 years ago
DelphiExpert
:mrgreen: WAKAKAKAKA.... salah tangkep nih gue. maklum pada bocor ni kepala :mrgreen:
Yang itu tho maksudnye wakakak

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 !!!

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.

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

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...
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
reply |
Report Obsolete
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
Last Articles
Last Topic
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #5: UX: Research, Design and Engineer
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #4: Obrolan Ringan Seputar IT
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #2: Membuat Sendiri SMART HOME
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #3: RADically Fast and Easy Mobile Apps Development with Delphi
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #1: Pemanfaatan Artificial Intelligence di Masa Covid-19
by LuriDarmawan in Tutorial & Community Project more 4 years ago - Tempat Latihan Posting
by LuriDarmawan in OOT more 5 years ago - Archive
- Looping lagi...
by idhiel in Hal umum tentang Pascal Indonesia more 12 years ago - [ask] koneksi ke ODBC user Dsn saat runtime dengan ado
by halimanh in FireBird more 12 years ago - Validasi menggunakan data tanggal
by mas_kofa in Hal umum tentang Pascal Indonesia more 12 years ago
Random Topic
- Script untuk tau komp di jaringan (komp lain) hidup apa gak
by Starboard in Enginering more 19 years ago - bagaimana cara mengecek client masih terhubung atau tidak ?
by stoopid in Tip n Trik Pemrograman more 18 years ago - Spasi kosong di record MsSQL...
by Random in MsSQL more 17 years ago - Masalah Dalam Menghitung Expired Date...
by ii_irwan in Hal umum tentang Pascal Indonesia more 15 years ago - e book delphi .net
by prakasiwi in OOT more 19 years ago - Beli Turbo Delphi dimana ya ?
by jrp in OOT more 18 years ago - Coding cekeremes.
by mambamaestro in Enginering more 17 years ago - tebak-tebakan
by _aa_ in OOT more 17 years ago - coding utk find folder??
by imunk in Tutorial & Community Project more 19 years ago - fungsi scanline
by Casanova in Multimedia & Graphic Enhancement more 18 years ago