如何使用For LOOP依次打开2个文件 [英] How to Open 2 Files one after the other using For LOOP
本文介绍了如何使用For LOOP依次打开2个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用for循环一一打开具有相同扩展名的文件
我想使用for循环在消息框中逐一显示其中的内容.
在Advance中感谢
How do I Open files of the same extension one by one using a for loop
I want to display the content in them in a message box one by one using a for loop.
Thanks in Advance
推荐答案
如果很简单,但是具有相同扩展名的文件"和Directory.GetFiles存在一个问题—它无法正常工作期待.
您将在这里找到说明和解决方法:
Directory.Get.Files搜索模式问题 [ ^ ].
要读取文件,请使用System.IO.StreamReader
,尤其是System.IO.StreamReader.ReadToEnd
.
—SA
If would be easy, but there is one problem with "files of the same extension" and Directory.GetFiles — it does not work as one can expect.
You will find the explanation and the resolution here:
Directory.Get.Files search pattern problem[^].
For reading the file, useSystem.IO.StreamReader
, in particular,System.IO.StreamReader.ReadToEnd
.
—SA
这是一个相对简单的答案,我相信我们以前有过这个答案,简单的搜索即可为您找到答案:
http://msdn.microsoft.com/en-us/library/bb513869.aspx [ ^ ]
可以使用一个简单的if块轻松地对此进行修改,该块检查FileInfo Extension属性.
希望对您有所帮助,请下次尝试搜索,
埃德:)
我也发现了一些VB解决方案:
http://stackoverflow.com/questions/4607912/visual-basic-iterate-a-文件夹文件 [ ^ ]
http://support.microsoft.com/kb/306666 [ http://www.dreamincode.net/forums/topic/118490-looping-through-files / [^ ]
This is a relatively simple answer and I believe we''ve had this one before, a simple search would get you the answer:
http://msdn.microsoft.com/en-us/library/bb513869.aspx[^]
This can easily be modified with a simple if block that checks the FileInfo Extension property.
Hope this helps, try searching next time,
Ed :)
A few VB solutions I found as well :
http://stackoverflow.com/questions/4607912/visual-basic-iterate-a-folders-files[^]
http://support.microsoft.com/kb/306666[^]
http://www.dreamincode.net/forums/topic/118490-looping-through-files/[^]
这篇关于如何使用For LOOP依次打开2个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文