[英]Reading multiple Text files
Just a question, I'am using c# mvc for a project and I have this requirement of getting several text files from a particular path (network path to be precised - eg: \\10.0.0.1\\SharedFolder). 只是一个问题,我正在为项目使用c#mvc,并且我有从特定路径(要精确调整的网络路径-例如:\\ 10.0.0.1 \\ SharedFolder)中获取多个文本文件的要求。 Now, each text files has different text formats and what I have to do is to get any existing files from that path folder and create a single text file for all the text files.
现在,每个文本文件都有不同的文本格式,我要做的是从该路径文件夹中获取任何现有文件,并为所有文本文件创建一个文本文件。
I was already looking at the option of using "Browse Folder" button, however, I wasn't getting any progress on how to achieve this. 我已经在考虑使用“浏览文件夹”按钮的选项,但是,在实现这一目标方面没有任何进展。
Thanks in advance. 提前致谢。
This is how I would do it => 这就是我要做的=>
Iterate through each file in the directory using the .net Directory class. 使用.net Directory类遍历目录中的每个文件。
For each file: Use the Textreaderclass to read each line Use the Textwriter class to write each line to your designated file 对于每个文件:使用Textreader类读取每一行使用Textwriter类将每一行写入指定的文件
Let me know if you still can't figure it out! 让我知道您是否仍然无法解决!
Yeah you can, 是的,你可以,
using (TextWriter writer = File.CreateText("C:\\Output.txt"))
{
//WRITE WHATEVER YOU WANT TO WRITE.
}
Just replace "C:\\Output.txt" with the directory you want. 只需将“ C:\\ Output.txt”替换为所需目录即可。
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.