文件夹里面所有可读文本文件,读出来,写到一个新文件中。
具体的也没什么好说的。就是你需要把大量的文件夹下面的代码,写到文档中。用我这个就好了。自己改改就行。看看注释就能改了。
缺点在于界面不友好。写得比较死。呵呵。
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Web;
5
using System.Runtime.Remoting;
6
using System.Runtime.Remoting.Lifetime;
7
using System.IO;
8
using System.Collections;
9
10
namespace ConsoleApplication2
11

{
12
class FileRead
13
{
14
static void Main(string[] args)
15
{
16
//写的比较死,有需要的自己零活修改。
17
Test();
18
}
19
20
Tesst#region Tesst
21
22
public static string[] GetFiles(string dir)
23
{
24
//get fileList 这种方法提供多级搜索。* 表示所有文件。
25
string[] files = Directory.GetFiles(dir,"*",SearchOption.AllDirectories);
26
27
return files;
28
}
29
30
public static void Read2Write(string sF, string tF)
31
{
32
using (StreamReader sr = new StreamReader(sF))
33
{
34
String line = "";
35
line = sr.ReadToEnd();
36
sr.Close();
37
string newfile = tF;
38
StreamWriter sw = new StreamWriter(newfile, true);
39
sw.Write(line);
40
sw.Close();
41
}
42
}
43
44
public static void Test()
45
{
46
string[] list = GetFiles(@"D:\1\OTLA");//目标目录
47
48
foreach (string dir in list)
49
{
50
Read2Write(dir, @"D:\result.txt");//结果目录
51
}
52
}
53
54
#endregion
55
56
}
57
58
}

2

3

4

5

6

7

8

9

10

11



12

13



14

15



16

17

18

19

20


21

22

23



24

25

26

27

28

29

30

31



32

33



34

35

36

37

38

39

40

41

42

43

44

45



46

47

48

49



50

51

52

53

54

55

56

57

58
