hi guys is anyone have an idea how to find total no of files and folder under perticular path..
I have thought ofbut how to use it in deep hierarchy...VB Code:
Directory.GetFiles("..").Length
thanks
Printable View
hi guys is anyone have an idea how to find total no of files and folder under perticular path..
I have thought ofbut how to use it in deep hierarchy...VB Code:
Directory.GetFiles("..").Length
thanks
Are you using .NET 2.0? If so then Directory.GetFiles and .GetDirectories each have a new overload that allows you to specify that you want to search all subfolders too. If not then you'll have to write your own recursive method to search subfolders, which is not difficult. Please specify which version you're using in future.
Well Im using .NET 2003. However, Im intended to move to 2005... and if there is an overloaded method of GetFiles in .NET 2.0 then i'm really very happy.. :)
thanks
thanks
thank u very much
Ok..It's working fine .. but i want to count only those file not having the Attribute Hidden or System... Any Idea ?
You could do something like this:
StephanCode:if(File.GetAttributes(path) != System.IO.FileAttributes.Hidden || File.GetAttributes(path) != System.IO.FileAttributes.System)
Ok .. But how to use it with the coding like this :
VB Code:
Int32 Totalcount = System.IO.Directory.GetDirectories("c:/", "*", System.IO.SearchOption.AllDirectories).Length;
You cannot do direct comparisons of file attributes like that because it is a compound value. You'd need to do something like this:Code:string[] files = System.IO.Directory.GetFiles("folder path here");
int fileCount = files.Length;
foreach (string file in files)
{
System.IO.FileAttributes attr = System.IO.File.GetAttributes(file);
// These two conditions could be combined but I've separated them for clarity.
// You must perform a bit-wise AND to extract individual values from the composite value.
if (attr & System.IO.FileAttributes.System == System.IO.FileAttributes.System)
{
fileCount--;
}
else if (attr & System.IO.FileAttributes.Hidden == System.IO.FileAttributes.Hidden)
{
fileCount--;
}
}
MessageBox.Show(fileCount + " files found.");
Finally I installed .NET 2005 .. and hey the above solution is working fine with minor changes.. thanks dude