프로그램/C# - Study / / 2010. 10. 13. 15:15

C# - Ex24DirectoryAndFile

반응형

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Ex24DirectoryAndFile
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "C:\\windows";

            if(Directory.Exists(path)) // 경로에 있는 확인 하는것 Exists
            {
                DirectoryInfo dir = new DirectoryInfo(path);
                DirectoryInfo[] subdirs = dir.GetDirectories();
                foreach(DirectoryInfo subdir in subdirs)
                {
                    Console.WriteLine("{0, -25}{1, -7}{2, 12}{3}",
                        subdir.LastAccessTime.ToString("yyyy-mm-dd hh:mm"),
                        "<DIR>",
                        "",
                        subdir.Name);
                }
                Console.ReadLine();
                FileInfo[] files = dir.GetFiles();
                foreach(FileInfo file in files)
                {
                    Console.WriteLine("{0, -25}{1, -7}{2, 12}{3}",
                        file.LastAccessTime.ToString("yyyy-mm-dd hh:mm"),
                        "",
                        file.Length,
                        file.Name);
                }

               
            }
            else
            {
                Console.WriteLine("존재하지 않는 경로입니다.");
            }
           

           
        }
    }
}


반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유