C# 创建txt文件 文件夹 获取目录

---恢复内容开始---

1,获取程序的基目录

string path = Aain.CurrentDomain.BaseDirectory;

2,获取指定目录下的所有文件

var files = from f in Directory.EnumerateFiles(@"D:\MyProjects\Test\") select f;

3,在“2”的基础上对文件集操作

 foreach (var file in files)
 {
     string fileName = Path.GetFileName(file);
  }

 4,判断是否存在此文件夹,没有就新建一个

        string filePath= AppDomain.CurrentDomain.BaseDirectory + @"text\folername";
        if (!Directory.Exists(filePath))
        {
             Directory.CreateDirectory(filePath);
        }

5,判断此文件是否存在,没有就新建

            string filename=@"D:\test.txt";
            if (System.IO.File.Exists(filename))
                return false;
            else
            {
                System.IO.File.Create(filename).Close();
                return true;
            }

 6,删除文本文件

System.IO.File.Delete("D:\test.txt");

 

posted @ 2019-04-25 17:59  简辞  阅读(2259)  评论(0)    收藏  举报