I had to split some text reports (csv format) that are read by colleagues in Excel just the other day. Excel can only read ~65k lines on one sheet, but the reports were ~100k lines - so I had to split the files in two. The reports are generated via script; so I decided to write another script to split the files at around the 60K mark. Hope this can save someone else some time :)
The script below takes as arguements; source filename, base filename and the target directory.
if WScript.Arguments.Count > 0 then ' retrieve the command line arguments sourceFile = WScript.arguments.Item(0) basename = WScript.arguments.Item(1) targetDir = WScript.arguments.Item(2) set objFSO = CreateObject("Scripting.FileSystemObject") ' check the file exists if objFSO.FileExists( sourceFile ) then WScript.Echo ("input file exists...") ' new files new1 = targetDir + "\" + basename + "_" + "a." + objFSO.GetExtensionName(sourceFile) new2 = targetDir + "\" + basename + "_" + "b." + objFSO.GetExtensionName(sourceFile) set fs = CreateObject("Scripting.FileSystemObject") set w1 = objFSO.CreateTextFile(new1, True) set w2 = objFSO.CreateTextFile(new2, True) isNotSplit = True with fs.OpenTextFile(sourceFile) while Not .AtEndOfStream if .Line < 60000 then w1.WriteLine .ReadLine else w2.WriteLine .ReadLine if( isNotSplit ) then isNotSplit = False WScript.Echo ("file being split...") end iF end if wend .Close end with w1.Close w2.Close if( isNotSplit ) then WScript.Echo ("input file not split...") else WScript.Echo ("input file split...") end if else WScript.Echo ("input file does not exist...") end if WScript.Echo ("finished!") end if