-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopyViaVS2012.txt
101 lines (93 loc) · 3.21 KB
/
CopyViaVS2012.txt
1
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <string>
#include <iostream>
#include <stdio.h>
#define LENGTH 100000
using namespace std;
int main(int argc,char *argv[])
{
FILE *CommandFile,*SubFile,*MainFile;
string ReadCommand,FileRead,FilePath;
string::size_type PosBegin=0,PosEnd=0,FileReadBegin=0,FileReadEnd=0;
FilePath="d:\\CpRead.txt";
FilePath=argv[1];
int flag;
flag=1;
flag=atoi(argv[2]);
cout<<FilePath<<endl;
char readfile[LENGTH];
CommandFile=fopen(FilePath.c_str(),"r");
//假定ID间没有空格,but,现在有空格了。。。。。。if love、、、、、、
int test=0;
char* p;
while(!feof(CommandFile))
{
p = fgets(readfile,LENGTH,CommandFile);
if(p==NULL)
{
continue;//当读取失败或者读至文件结束符时跳过
}
FileRead+=readfile;
}
while(FileReadBegin<FileRead.length())
{
if(FileRead.length()<5)
{
cout<<"FileRead.length()<5"<<endl;
return 0;
}
FileReadEnd=FileRead.find("\n",FileReadBegin);
ReadCommand=FileRead.substr(FileReadBegin,FileReadEnd-FileReadBegin);
PosBegin=ReadCommand.find("&&&");
string subFileStr=ReadCommand.substr(0,PosBegin);
string mainFileStr=ReadCommand.substr(PosBegin+3,ReadCommand.length());
string readSubstr;
MainFile=fopen(mainFileStr.c_str(),"w");
PosBegin=0;
PosEnd=0;//归零
if(MainFile==NULL)
{
FileReadBegin=FileReadEnd+1;
continue;
}
while(PosEnd<subFileStr.length())
{
PosEnd=subFileStr.find("###",PosBegin);
readSubstr=subFileStr.substr(PosBegin,PosEnd-PosBegin);
PosEnd+=3;
PosBegin=PosEnd;
SubFile=fopen(readSubstr.c_str(),"r");
test++;//测试
if(SubFile!=NULL)
{
while(!feof(SubFile))
{
fgets(readfile,LENGTH-2,SubFile);
fputs(readfile,MainFile);
}
fclose(SubFile);
}
else
{
cout<<"Error : ";
cout<<readSubstr<<" Couldn't open"<<endl;
}
if(flag==0)
{
remove(readSubstr.c_str());
}
}
if(test%100==0)
{
cout<<test<<" file has readen"<<endl;
}
fclose(MainFile);
if(FileReadEnd==-1)
{
cout<<"File Read over"<<endl;
return 0;
}
FileReadBegin=FileReadEnd+1;
}
cout<<"endl";
return 0;
}