Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il

Hostgator - Save 50% Off Your New Optimized WordPress Hosting With Coupon: WDA50

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Dedicated Hosting Superb Internet

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,580 questions

9,399 answers

573 users

How to convert FileInfo to Directory in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static Dictionary<string, object> FileInfoToDictionary(object o)
        {
            return o.GetType().GetProperties().ToDictionary(x => x.Name, x => x.GetValue(o));
        }
        static void Main(string[] args)
        {
            var fileNames = Directory.EnumerateFiles("c:\\xampp");

            foreach (string fn in fileNames)
            {
               Console.WriteLine("-------------------------------------------------------");
               FileInfo fi = new FileInfo(fn);
               var dic = FileInfoToDictionary(fi); 
               foreach (var item in dic.AsEnumerable())
               {
                  Console.WriteLine(string.Format("{0}: {1}", item.Key, item.Value.ToString()));
               }
            }
        }
    }
}


/*
run:
    
IsReadOnly: False
Exists: True
FullName: c:\xampp\mysql_start.bat
Extension: .bat
CreationTime: 13/06/2016 11:30:53
CreationTimeUtc: 13/06/2016 08:30:53
LastAccessTime: 13/06/2016 11:30:53
LastAccessTimeUtc: 13/06/2016 08:30:53
LastWriteTime: 07/06/2013 14:15:50
LastWriteTimeUtc: 07/06/2013 11:15:50
Attributes: Archive
-------------------------------------------------------
Name: mysql_stop.bat
Length: 220
DirectoryName: c:\xampp
Directory: c:\xampp
IsReadOnly: False
Exists: True
FullName: c:\xampp\mysql_stop.bat
Extension: .bat
CreationTime: 13/06/2016 11:30:53
CreationTimeUtc: 13/06/2016 08:30:53
LastAccessTime: 13/06/2016 11:30:53
LastAccessTimeUtc: 13/06/2016 08:30:53
LastWriteTime: 07/06/2013 14:15:52
LastWriteTimeUtc: 07/06/2013 11:15:52
Attributes: Archive
-------------------------------------------------------
Name: properties.ini
Length: 771
DirectoryName: c:\xampp
Directory: c:\xampp
IsReadOnly: False
Exists: True
FullName: c:\xampp\properties.ini
Extension: .ini
CreationTime: 13/06/2016 11:31:50
CreationTimeUtc: 13/06/2016 08:31:50
LastAccessTime: 13/06/2016 11:31:50
LastAccessTimeUtc: 13/06/2016 08:31:50
LastWriteTime: 13/06/2016 11:31:50
LastWriteTimeUtc: 13/06/2016 08:31:50
Attributes: Archive
-------------------------------------------------------
Name: readme_en.txt
Length: 7566
DirectoryName: c:\xampp
Directory: c:\xampp
IsReadOnly: False
Exists: True
FullName: c:\xampp\readme_en.txt
Extension: .txt
CreationTime: 13/06/2016 11:30:53
CreationTimeUtc: 13/06/2016 08:30:53
LastAccessTime: 13/06/2016 11:30:53
LastAccessTimeUtc: 13/06/2016 08:30:53
LastWriteTime: 12/05/2016 18:03:26
LastWriteTimeUtc: 12/05/2016 15:03:26
Attributes: Archive
-------------------------------------------------------
Name: RELEASENOTES
Length: 1970
DirectoryName: c:\xampp
Directory: c:\xampp
IsReadOnly: False
Exists: True
FullName: c:\xampp\RELEASENOTES
Extension:
CreationTime: 13/06/2016 11:30:53
CreationTimeUtc: 13/06/2016 08:30:53
LastAccessTime: 13/06/2016 11:30:53
LastAccessTimeUtc: 13/06/2016 08:30:53
LastWriteTime: 12/05/2016 18:13:18
LastWriteTimeUtc: 12/05/2016 15:13:18
Attributes: Archive
-------------------------------------------------------
Name: service.exe
Length: 60928
DirectoryName: c:\xampp
Directory: c:\xampp
IsReadOnly: False
Exists: True
FullName: c:\xampp\service.exe
Extension: .exe
CreationTime: 13/06/2016 11:30:52
CreationTimeUtc: 13/06/2016 08:30:52
LastAccessTime: 13/06/2016 11:30:52
LastAccessTimeUtc: 13/06/2016 08:30:52
LastWriteTime: 30/03/2013 15:29:00
LastWriteTimeUtc: 30/03/2013 12:29:00
Attributes: Archive
-------------------------------------------------------
...

*/

 




answered Jul 13 by avibootz
...