Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void CreateOtherFiles(List<string> listOfLines, int maxLinesPerFile, string path)
- {
- int numOfFiles = listOfLines.Count / maxLinesPerFile;
- if (listOfLines.Count % maxLinesPerFile != 0)
- {
- numOfFiles++;
- }
- int currentLocationInList = 0;
- for (int i = 1; i <= numOfFiles; i++)
- {
- try
- {
- path = Path.GetFileNameWithoutExtension(path);
- using (StreamWriter sw = new StreamWriter(Path.Combine(Environment.CurrentDirectory, path + "-" + i + ".txt")))
- {
- for (int j = 0; j < maxLinesPerFile; j++)
- {
- if (listOfLines.Count - currentLocationInList > 0)
- {
- sw.WriteLine(listOfLines[currentLocationInList]);
- currentLocationInList++;
- }
- else
- {
- break;
- }
- }
- }
- }
- catch (IOException ex)
- {
- Console.WriteLine("There was an error writing to file " + ex.Message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement