|
-
Apr 27th, 2006, 01:21 AM
#1
Thread Starter
Hyperactive Member
URGENT : How to find total files + folder
hi guys is anyone have an idea how to find total no of files and folder under perticular path..
I have thought of
VB Code:
Directory.GetFiles("..").Length
but how to use it in deep hierarchy...
thanks
-
Apr 27th, 2006, 01:59 AM
#2
Re: URGENT : How to find total files + folder
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.
-
Apr 27th, 2006, 03:15 AM
#3
Thread Starter
Hyperactive Member
Re: URGENT : How to find total files + folder
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
-
Apr 27th, 2006, 03:35 AM
#4
Thread Starter
Hyperactive Member
Re: URGENT : How to find total files + folder
Ok..It's working fine .. but i want to count only those file not having the Attribute Hidden or System... Any Idea ?
-
Apr 27th, 2006, 03:51 AM
#5
Hyperactive Member
Re: URGENT : How to find total files + folder
You could do something like this:
Code:
if(File.GetAttributes(path) != System.IO.FileAttributes.Hidden || File.GetAttributes(path) != System.IO.FileAttributes.System)
Stephan
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Apr 27th, 2006, 04:20 AM
#6
Thread Starter
Hyperactive Member
Re: URGENT : How to find total files + folder
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;
-
Apr 27th, 2006, 04:21 AM
#7
Re: URGENT : How to find total files + folder
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.");
-
Apr 28th, 2006, 03:17 AM
#8
Thread Starter
Hyperactive Member
Re: URGENT : How to find total files + folder
Finally I installed .NET 2005 .. and hey the above solution is working fine with minor changes.. thanks dude
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|