Mehmet Akif Akkus

Bir Bilgisayar Mühendisinin Günlüğü

Sunday, Aug 01st

Last update:04:49:41 AM GMT

Headlines:
RSS
You are here: Projeler Programlama Bil341_0910_Rekürsif Dolasiım

Bil341_0910_Rekürsif Dolasiım

e-Posta Yazdır PDF
Aşağıdaki kod sDir kök dizininde verilen tüm dosyaları lstFounds adlı listeye atacaktır. 

Read More
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


void DirSearch(string sDir) 
{
try
{
foreach (string d in Directory.GetDirectories(sDir))
{Read More
foreach (string f in Directory.GetFiles(d, txtFile.Text))
{
lstFilesFound.Items.Add(f);
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
} 


Aşağıdaki kod ise yukarıdakini belirlenen bir seviyeye kadar inerek yapmaktadır. Dosyaları ekrana basmaktadır
Burada recursionLv1 inilecek seviyeyi belirlmektedir
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
 
public static void ProcessDir(string sourceDir, int recursionLvl) 
{
 if (recursionLvl<=HowDeepToScan)
 {
 // Process the list of files found in the directory. 
 string [] fileEntries = Directory.GetFiles(sourceDir);
 foreach(string fileName in fileEntries)
 {
 // do something with fileName
 Console.WriteLine(fileName);
 }
 
 
// Recurse into subdirectories of this directory.
string [] subdirEntries = Directory.GetDirectories(sourceDir);
foreach(string subdir in subdirEntries)
// Do not iterate through reparse points
if ((File.GetAttributes(subdir) &
FileAttributes.ReparsePoint) !=
FileAttributes.ReparsePoint)
 
ProcessDir(subdir,recursionLvl+1);
}
}
 
 

 



Related news items:
Newer news items:
Older news items:

Yorumlar  

 
0 # İbrahim Ateş 2010-02-01 22:29
Akif güzel çalışma ama hala recursif diyon ya :) özyineli de şuna be ani :))) Bu arada bizim siteye de beklerim
http://null-pointerexception.blogspot.com/
Cevap | Alıntı | Alıntı
 

Yorum ekle


Güvenlik kodu
Yenile