Const c_fsoForReading = 1
Const c_lngMaxLines = 65535
Set objDialog = CreateObject("UserAccounts.CommonDialog")
With objDialog
.Filter = "Text Files|*.txt"
.InitialDir = "D:\"
intResult = .ShowOpen
End With
If intResult = 0 Then
WScript.Quit
Else
'// do nothing
'// WScript.Echo objDialog.FileName
End If
strFullFileName = objDialog.Filename
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFileInput = objFSO.OpenTextFile(strFullFileName, c_fsoForReading)
p = InStrRev(strFullFileName,"\")
strPath = Left(strNewFileName, p)
strFileName = Right(strFullFileName, Len(strFullFileName) - p)
d = InStrRev(strFileName,".")
strBaseFileName = Left(strFileName,d - 1)
strExt = Right(strFileName,Len(strFileName) - d + 1)
Do While objTextFileInput.AtEndOfStream <> True
f = f + 1
m = 10
strNewFileName = strPath & strBaseFileName & " - " & CStr(f) & strExt
Set objTextFileOutput = objFSO.CreateTextFile(strNewFileName, TRUE)
r = 1
Do Until r > c_lngMaxLines Or objTextFileInput.AtEndOfStream
strLine = objTextFileInput.ReadLine
r = r + 1
objTextFileOutput.WriteLine strLine
'// This part not critical.
'// I just like seeing what's going on.
If r Mod m = 0 Then
WScript.echo FormatNumber( r, 0, FALSE, FALSE, TRUE) & " lines read" '// & vbcrlf & "m = " & m
Select Case true
Case r >= 250000 : m = 50000
Case r >= 50000 : m = 25000
Case r >= 20000 : m = 10000
Case r >= 5000 : m = 2500
Case r >= 500 : m = 1000
Case r >= 50 : m = 100
End Select
End If
Loop
objTextFileOutput.Close
Loop
objTextFileInput.Close
WScript.Echo "Done"