C
Chaitanya Phani Kishore Tallapragada
Guest
I am trying to find count of all files in folder day wise showed in below image.(expected output)
Could you please help me how to loop all the files in a directory (Folder) to get the count of files and CreatedDate(Day wise).
Attempt : Below is the main method in C Sharp class
static void Main(string[] args)
{
Program p = new Program();
var directory = new DirectoryInfo(@"C:\Test\TestFileCount");
var myFile = (from f in directory.GetFiles()
orderby f.LastWriteTime descending
select f).First();
List<FileInfo> FilesInNovember = p.GetFilesByDate(15, @"C:\Test\TestFileCount");
Console.WriteLine("Number of files " + "\t" + FilesInNovember.Count + "\t" + "On" +"\t" + myFile.LastWriteTime.ToString());
Console.ReadLine();
}
GetFilesByDate method defination
private List<FileInfo> GetFilesByDate(int DayToGet, string directoryPath)
{
DirectoryInfo dir = new DirectoryInfo(directoryPath);
// note use of the option to search sub-directories
FileInfo[] theFiles = dir.GetFiles("*", SearchOption.AllDirectories);
return theFiles.Where(fl => fl.CreationTime.Day == DayToGet).ToList();
}
Some links with similar output requirement, but in VB.Net . Getting difficulty to understand it.http://www.codepal.co.uk/show/Show_file_count_and_filesizes_grouped_by_monthly_creation_date_in_ASPNET
Expected Output and Current out put with above code:
CPK
Continue reading...
Could you please help me how to loop all the files in a directory (Folder) to get the count of files and CreatedDate(Day wise).
Attempt : Below is the main method in C Sharp class
static void Main(string[] args)
{
Program p = new Program();
var directory = new DirectoryInfo(@"C:\Test\TestFileCount");
var myFile = (from f in directory.GetFiles()
orderby f.LastWriteTime descending
select f).First();
List<FileInfo> FilesInNovember = p.GetFilesByDate(15, @"C:\Test\TestFileCount");
Console.WriteLine("Number of files " + "\t" + FilesInNovember.Count + "\t" + "On" +"\t" + myFile.LastWriteTime.ToString());
Console.ReadLine();
}
GetFilesByDate method defination
private List<FileInfo> GetFilesByDate(int DayToGet, string directoryPath)
{
DirectoryInfo dir = new DirectoryInfo(directoryPath);
// note use of the option to search sub-directories
FileInfo[] theFiles = dir.GetFiles("*", SearchOption.AllDirectories);
return theFiles.Where(fl => fl.CreationTime.Day == DayToGet).ToList();
}
Some links with similar output requirement, but in VB.Net . Getting difficulty to understand it.http://www.codepal.co.uk/show/Show_file_count_and_filesizes_grouped_by_monthly_creation_date_in_ASPNET
Expected Output and Current out put with above code:
CPK
Continue reading...