Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am working in smart device applications.using web services generate x ml files. I want how to identify the how many files are there in one particular folder and ,how to identify how many images are there in one particular file in c#.net using in device applications?
Posted

Use System.IO.Directory.GetFiles. See http://msdn.microsoft.com/en-us/library/system.io.directory.aspx[^].

—SA
 
Share this answer
 
Try:
string[] files = Directory.GetFiles(path);
Console.WriteLine(files.Length);
 
Share this answer
 
Comments
shefeekcm 25-Jul-11 3:24am    
my 5
HI,
following is the simple way and its working:

C++
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(Server.MapPath(folderName));



SQL
if (dirInfo.Exists)
            {
int fileCount=dirInfo.GetFiles("*.*").Count()

}



Reply me if its working.... : )
 
Share this answer
 
v2
It might help you,

C#
public static Int32 HowManyFiles(string folderName)
{
    return Directory.Exists(folderName) ? Directory.GetFiles(folderName).Count() : 0;
}
public static Int32 HowManyImageFiles(string folderName)
{
    //Need to update the list according your situation.
    IList myList = new List<string>() { ".jpeg", ".jpg", ".gif", ".bmp" };
    return Directory.Exists(folderName) ? Directory.GetFiles(folderName).Where(item => myList.Contains(Path.GetExtension(item))).Select(item => item).Count() : 0;
}


usage:

C#
var result = HowManyFiles(@"C:\temp");
var resultWithImage = HowManyImageFiles(@"C:\temp");


:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900