如何让我的程序从特定目录中的几个文本文件中提取特定信息? [英] How do I make my program extract specific info from several text files in a specific directory?

查看:119
本文介绍了如何让我的程序从特定目录中的几个文本文件中提取特定信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他我尝试了几个代码但没有工作我正在使用一个小工具从我运行程序时从特定目录(我指定)中的几个文本文件中提取所有名字和姓氏。然后将所有这些名字和姓氏组合在一个文本文件中。 。那么我应该用什么代码让我的程序从所有文本文件中提取所有的名字和姓氏,并将它们组合在一个文本文件中。



我知道这不是你的工作写我的代码,但对不起,我是这个领域的新手,任何帮助都将不胜感激。



注意:应提示选择目录用户和组合列表(文本文件)应该被选中应该保存的位置。

提前致谢



我的尝试:



(到目前为止,我能够选择一个目录并仅从文本文件中提取名字和姓氏),我明白我应该实现一个循环,但for ...每个都不适用于我(问题就是我知道)

Him I tried several codes but none worked I am working of a little tool to extract all First name and last name from several text files in a specific directory (that i specify) whenever i run the program. then combine all these first name and last name in one text file. . So what code should i use to make my program extract all the firstname and lastname from all text files and combine them in one text file.

I know it's not your job to write my code but I'm sorry I'm new to this field and any help would be appreciated.

Note: The directory should be prompted to be selected by the user, and the combined list (text file) should b prompted to be selected where it should be saved.
Thanks in advance

What I have tried:

(So far i was able to select a directory and extracting from the first name and last name from the text file only), i understand that i should implement a loop but the for... each is not working for me (the problem is me i know)

推荐答案

您可以使用 Directory.GetFiles()来获取所有文件到数组中,请参阅: [ dotnetperls ]

然后对于数组中的每个文件,使用 Path.GetExtension()检查它是否是.txt文件。

如果foreach循环出现问题,请使用表示 while 循环。

要保存生成的文本文件,请参阅: [ SaveFileDialog ]
You can use Directory.GetFiles() to get all files into an array, see: [dotnetperls]
Then for each file in the array use Path.GetExtension() to check if it is a ".txt" file.
If the foreach loop gives problems, use a for or while loop.
For saving the resulting text file, see: [SaveFileDialog]


这篇关于如何让我的程序从特定目录中的几个文本文件中提取特定信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆