C# get files and write the files full name in txt

 static void GetAllFiles()
        {
            string path = "filepath";
            var allFiles = Directory.GetFiles(path);
            string fileName = "file.txt";

            using (FileStream fStream = File.Create(fileName))
            { }

            using (FileStream fStream = File.Create("file.txt"))
            {
                using (StreamWriter writer = new StreamWriter(fStream, Encoding.UTF8))
                {
                    foreach (var file in allFiles)
                    {
                        writer.WriteLine(file);
                    }
                }
            }
        }

 

posted @ 2019-10-18 15:00  FredGrit  阅读(126)  评论(0编辑  收藏  举报