Wednesday, December 24, 2014

Get file information of all files in a folder

Description:
Following code can be used to get file information in a folder:

static void getfileinfo()
{

    string path = "D:\\test\\";
    String[] filenames = Directory.GetFiles(path, "*.txt");
    string file = string.Empty;
    string name = string.Empty;
    DateTime creationTime;
    DateTime lastWriteTime;
    DateTime lastAccessTime;
    foreach (string str in filenames)
    {

        creationTime = File.GetCreationTime(str);
        lastWriteTime = File.GetLastWriteTime(str);
        lastAccessTime = File.GetLastAccessTime(str);

        file = str.Substring(str.LastIndexOf("\\") + 1);
        name = file.Substring(0, file.IndexOf('.')).Replace("-", " ").Trim();
    }

}

No comments:

Post a Comment