I'm writing something in C# and I need to find a way to split a text file into more files with the number of lines in the file being equivalent to a user input.
Example : file a had 1000 lines in it and I want the code to ask the user for a number and then use that number to make more files like this a = 1000 lines .
Then after the code has run with the input of 300
a = 300 lines
b = 300 lines
c = 300 lines
d = 300 lines
e = 300 lines
Repeat that until the original file has been split into more files all with 300 lines .
This is what I have so far
var file = File.ReadAllLines(ofd.FileName);
Console.Write("> ");
int userlinestosplit = int.Parse(Console.ReadLine());
ArrayList fileA = new ArrayList();
for (int i = 0; i < userlinestosplit; i++)
{
string line = file[i];
fileA.Add(line);
}
int linesleft = file.Length - userlinestosplit;
ArrayList fileB = new ArrayList();
for (int i = linesleft; i < file.Length; i++)
{
string line = file[i];
fileB.Add(line);
}
string[] fileAArr = (string[])fileA.ToArray(typeof(string));
string[] fileBArr = (string[])fileB.ToArray(typeof(string));
string resdir = "results";
string modir = "splited";
Directory.CreateDirectory(resdir);
Directory.SetCurrentDirectory(resdir);
Directory.CreateDirectory(modir);
Directory.SetCurrentDirectory(modir);
File.WriteAllLines("FA.txt", fileAArr);
File.WriteAllLines("FB.txt", fileBArr);
Console.ReadKey();
Any help would be greatly appreciated