폴더 당 긴 텍스트 파일 목록 (약 80-100 개 파일)이 있습니다. 나는 매 4 개의 텍스트 파일을 하나의 텍스트 파일로 결합해야한다. 각 텍스트 파일은 별도의 SQL 삽입 명령이므로 첫 번째 4 개의 텍스트 파일의 첫 번째 줄을 출력 파일에 보관해야합니다 (INSERT INTO 데이터베이스 (value1, value2, value3) VALUES). 나머지 3 개의 파일은 건너 뜁니다 첫 번째 줄에는 값이 있습니다.많은 텍스트 파일을 4 개의 그룹으로 결합하는 방법
내가 겪고있는 문제는 4 개의 파일 중 마지막 파일을 결합 할 때 마지막 파일의 절반 만 새 결합 파일에 복사한다는 것입니다.
한 파일에 3 개의 파일 또는 2 개의 파일 만 결합하려고해도. 마지막 파일의 약 절반 만 복사합니다.
여기 내 코드입니다.
fourCount
은 네 번째 텍스트 파일이 결합 된시기를 나타냅니다.
string[] array2 = sqlInsertList.ToArray();
StreamWriter outfile3 = new StreamWriter(folderPath.Text + "\\" + count + ".txt");
count++;
foreach (string dirFileName in array2)
{
StreamReader readFile = new StreamReader(dirFileName);
string readFromFile = readFile.ReadLine();
if(fourCount == 1)
{
outfile3 = new StreamWriter(folderPath.Text + "\\" + count + ".txt");
outfile3.WriteLine(readFromFile);
}
while(!readFile.EndOfStream)
{
readFromFile = readFile.ReadLine();
outfile3.WriteLine(readFromFile);
}
count++;
if(fourCount == 4)
{
outfile3.WriteLine(";");
fourCount = 1;
}
else
{
fourCount++;
}
}
나는 그것을 닫은 후에 잘 작동했다! 감사! – user908759