{"id":178,"date":"2009-02-10T02:46:00","date_gmt":"1970-01-01T00:00:00","guid":{"rendered":"http:\/\/www.yazilimmutfagi.com\/?p=178"},"modified":"2009-02-10T02:46:00","modified_gmt":"1970-01-01T00:00:00","slug":"dizin-icerisindeki-klasor-ve-dosyalari-listeleme","status":"publish","type":"post","link":"https:\/\/www.yazilimmutfagi.com\/index.php\/2009\/02\/10\/dizin-icerisindeki-klasor-ve-dosyalari-listeleme\/","title":{"rendered":"Dizin I\u00e7erisindeki Klas\u00f6r ve Dosyalari Listeleme."},"content":{"rendered":"<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\"><span style=\"font-size: small; font-family: Calibri;\">Bu makalemizde dizinler i&ccedil;indeki dosyalari ve klas&ouml;rleri listeleyen basit bir program yazacagiz. Programin anlatiminin yani sira yazdigimiz projeyi de indirerek inceleyebilirsiniz. Projeyi <a href=\"http:\/\/www.yazilimmutfagi.com\/Makale\/Img\/Sabri\/1_12_DosyaIslemleri.rar\">buradan <\/a>indirebilirsiniz. Proje kaynak kodlarini ekledigim i&ccedil;in makalede &ccedil;ok detaya girmeden ana kisimlari anlatmaya &ccedil;alisacagim. Detaylari projeyi indirerek inceleyebilirsiniz. Gelelim Programimizi yazmaya. <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\"><a href='www.yazilimmutfagi.com'>.<\/a><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\"><span style=\"font-size: small; font-family: Calibri;\"><a href=\"http:\/\/www.yazilimmutfagi.com\/Makale\/Img\/Sabri\/1_12_DosyaIslemleri.rar\">&Ouml;rnek Proje 38.5 KB<\/a><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\"><span style=\"font-size: small; font-family: Calibri;\">Ilk olarak yeni bir Windows Form Application a&ccedil;iyoruz. Ismini DosyaIslemleri olarak belirleyip projemizi gelistirmeye basliyoruz. Ilk olarak ekran tasarimi ile baslayalim. Asagidaki resimde g&ouml;rd&uuml;g&uuml;n&uuml;z gibi listeleyecegimiz dosyalarin bulundugu dizini se&ccedil;mek i&ccedil;in bir &ldquo;G&ouml;zat&rdquo;butonu ve se&ccedil;ilen dizini g&ouml;stermek i&ccedil;inde bir textbox ekledik. Se&ccedil;ilen dizindeki dosyalari liste halinde g&ouml;sterebilmek i&ccedil;in ise bir ListView kontrol&uuml;n&uuml; sayfanin altina koyduk. <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt;\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\"><span style=\"font-size: small; font-family: Calibri;\"><img decoding=\"async\" src=\"http:\/\/www.yazilimmutfagi.com\/Makale\/Img\/Sabri\/1_12_resim1.jpg\" alt=\"\" style=\"width: 431px; height: 315px;\" \/>G&ouml;zat butonuna bastigimiz zaman bir <\/span><span style=\"font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%; font-family: 'Courier New';\">FolderBrowserDialog <\/span><span style=\"font-size: small; font-family: Calibri;\">a&ccedil;arak <span style=\"\">&nbsp;<\/span>kullanicinin listelemek istedigi dizini se&ccedil;mesini saglayacagiz. <span style=\"\">&nbsp;<\/span>Bunun i&ccedil;in gozat butonumuzun Click eventini asagidaki gibi dolduruyoruz.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; color: blue; font-family: 'Courier New';\">private<\/span><span style=\"font-size: 10pt; font-family: 'Courier New';\"> <span style=\"color: blue;\">void<\/span> gozatButton_Click(<span style=\"color: blue;\">object<\/span> sender, <span style=\"color: rgb(43, 145, 175);\">EventArgs<\/span> e)<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">FolderBrowserDialog<\/span> fBrowser = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">FolderBrowserDialog<\/span>();<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>fBrowser.ShowDialog();<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">string<\/span> secilenDizin = fBrowser.SelectedPath;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>secilenDizinTextBox.Text = secilenDizin;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>DizinIceriginiListeyeEkle(secilenDizin);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\">}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\"><span style=\"font-size: small; font-family: Calibri;\">Sira geldi DizinIceriginiListeyeEkle fonksiyonunun i&ccedil;erigini doldurmaya. Bu fonksiyon parametre olarak aldigi dizin i&ccedil;erisindeki klas&ouml;r ve dosyalari bularak forma ekledigimiz listview &uuml;zerinde g&ouml;stermemizi saglayacak. O zaman gelin fonksiyonun i&ccedil;erisini yazalim. <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; color: blue; font-family: 'Courier New';\">private<\/span><span style=\"font-size: 10pt; font-family: 'Courier New';\"> <span style=\"color: blue;\">void<\/span> DizinIceriginiListeyeEkle(<span style=\"color: blue;\">string<\/span> dizin)<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">string<\/span>[] dizindekiKlasorler = <span style=\"color: rgb(43, 145, 175);\">Directory<\/span>.GetDirectories(dizin);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">string<\/span>[] dizindekiDosyalar = <span style=\"color: rgb(43, 145, 175);\">Directory<\/span>.GetFiles(dizin);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">foreach<\/span> (<span style=\"color: blue;\">string<\/span> klasor <span style=\"color: blue;\">in<\/span> dizindekiKlasorler)<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">DirectoryInfo<\/span> dirInfo = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">DirectoryInfo<\/span>(klasor);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">string<\/span> klasorAdi = dirInfo.Name;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">DateTime<\/span> olsTarihi = dirInfo.CreationTime;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">ListViewItem<\/span> item = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">ListViewItem<\/span>(klasorAdi);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>item.SubItems.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;Klas&ouml;r&quot;<\/span>);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>item.SubItems.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;&quot;<\/span>);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>item.SubItems.Add(olsTarihi.ToString(<span style=\"color: rgb(163, 21, 21);\">&quot;dd.MM.yyyy HH:mm&quot;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dizinIcerigiListView.Items.Add(item);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">foreach<\/span> (<span style=\"color: blue;\">string<\/span> dosya <span style=\"color: blue;\">in<\/span> dizindekiDosyalar)<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">FileInfo<\/span> fileInfo = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">FileInfo<\/span>(dosya);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">string<\/span> dosyaAdi = fileInfo.Name;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">long<\/span> byteBoyut = fileInfo.Length;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">DateTime<\/span> olsTarihi = fileInfo.CreationTime;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">ListViewItem<\/span> item = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">ListViewItem<\/span>(dosyaAdi);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>item.SubItems.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;Dosya&quot;<\/span>);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>item.SubItems.Add(byteBoyut.ToString());<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>item.SubItems.Add(olsTarihi.ToString(<span style=\"color: rgb(163, 21, 21);\">&quot;dd.MM.yyyy HH:mm&quot;<\/span>));<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dizinIcerigiListView.Items.Add(item);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 0pt; line-height: normal;\"><span style=\"font-size: 10pt; font-family: 'Courier New';\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt;\"><span style=\"font-size: 10pt; line-height: 115%; font-family: 'Courier New';\">}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt;\"><a href='www.yazilimmutfagi.com'>.<\/a><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\"><span style=\"font-size: small; font-family: Calibri;\">Yukardaki koddada g&ouml;rd&uuml;g&uuml;n&uuml;z gibi ilk olarak <\/span><span style=\"font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%; font-family: 'Courier New';\">Directory<\/span><span style=\"font-size: 10pt; line-height: 115%; font-family: 'Courier New';\">.GetDirectories, <span style=\"color: rgb(43, 145, 175);\">Directory<\/span>.GetFiles <\/span><span style=\"font-size: small; font-family: Calibri;\">&ouml;zelliklerini kullanarak dizin i&ccedil;erisindeki klasor ve dosyalari ayri ayri string diziler i&ccedil;erisine atiyoruz. Bundan sonra yapacagimiz tek sey bu dizi i&ccedil;erisindeki bilgileri d&uuml;zenleyerek listemize eklemek. GetDirectories ve GetFiles metotlari klasor veya dosyanin tam yolunu d&ouml;nd&uuml;r&uuml;r. &Ouml;rnegin: C:\\deneme\\deneme.txt gibi. Bize dosyanin tam adi, olusturulma tarihi ve boyutu lazim oldugu i&ccedil;in DirectoryInfo ve FileInfo siniflarini kullandik. Ekteki projeyi <a href=\"http:\/\/www.yazilimmutfagi.com\/Makale\/Img\/Sabri\/1_12_DosyaIslemleri.rar\">indirerek <\/a>kodlari daha iyi incelemenizi tavsiye ederim. <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\"><span style=\"font-size: small; font-family: Calibri;\">Bir sonraki makalemizde g&ouml;r&uuml;smek &uuml;zere&#8230;<\/span><\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Bu makalemizde dizinler i&#231;indeki dosyalari ve klas&#246;rleri listeleyen basit bir program yazacagiz. Programin anlatiminin yani sira yazdigimiz projeyi de indirerek inceleyebilirsiniz&#8230;.<\/p>\n","protected":false},"author":517,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[417],"tags":[6438,5697,6462,6250,6257,6350,6059,5110,4415,5160,5728,6081,6405,6353,6408,6437,4359],"_links":{"self":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/178"}],"collection":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/users\/517"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":0,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/178\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/media?parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/categories?post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/tags?post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}