asp.net gets the number of files and folders in the directory

  • 2020-05-10 17:56:52
  • OfStack

 
int j = 0; 
protected void Button1_Click(object sender, EventArgs e) 
{ 
DirectoryInfo dir = new DirectoryInfo(TextBox1.Text.ToString()); 
Label1.Text = GetAllFiles(dir).ToString(); 
}GetAllFiles Method for the custom method, the implementation of the entire folder file method. The code is as follows:  
public int GetAllFiles(DirectoryInfo dir) 
{ 
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); 
foreach (FileSystemInfo i in fileinfo) 
{ 
if (i is DirectoryInfo) 
{ 
GetAllFiles((DirectoryInfo)i); 
} 
else 
{ 
j++; 
} 
} 
return j; 
} 
//================================================= 
string[] Directorys = System.IO.Directory.GetDirectories("D:\\","*"); 
for(int i=0; i <Directorys.Length; i ) 
{ 
Response.Write(Directorys " <br/>"); 
} 
Response.Write(" Statistical catalogue: " Directorys.Length " a  <br/>--------- <br>"); 
//================================================= 
string[] Files = System.IO.Directory.GetFiles("D:\\","*"); 
for(int i=0; i <Files.Length; i ) 
{ 
Response.Write(Files " <br/>"); 
} 
Response.Write(" Statistical documents: " Files.Length " a  <br/>--------- <br>"); 

Related articles: