C#_FileInfo文件属性类和DirectoryInfo文件夹属性类

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

namespace CShapeTest
{
    class Start
    {
        static void Main(string[] args)
        {
            //// 文件属性类
            //FileInfo fileInfo = new FileInfo("Skill.json");

            //// 获取文件是否存在
            //bool bExists = fileInfo.Exists;
            //Console.WriteLine(bExists);

            //// 获取文件名
            //string name = fileInfo.Name;
            //Console.WriteLine(name);

            //// 获取文件上级路径
            //string directory = fileInfo.DirectoryName;
            //Console.WriteLine(directory);

            //// 获取文件是否只读
            //bool isReadOnly = fileInfo.IsReadOnly;
            //Console.WriteLine(isReadOnly);

            // 目录属性类
            DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\chen\Documents\Visual Studio 2013\Projects\CShapeTest\CShapeTest\bin\Debug");

            // 获取目录是否存在
            bool bExists = directoryInfo.Exists;
            Console.WriteLine(bExists);

            // 获取当前所在目录
            string name = directoryInfo.Name;
            Console.WriteLine(name);

            // 获取父级目录
            string parent = directoryInfo.Parent.ToString();
            Console.WriteLine(parent);

            // 获取根目录
            string root = directoryInfo.Root.ToString();
            Console.WriteLine(root);

            Console.ReadLine();
        }
    }
}

你可能感兴趣的:(C#)