我正在创建一个脚本来拆分 csv 文件,我想让用户输入文件被拆分为新文件的间隔。
我遇到的问题是,当我输入间隔时它没有分裂,但是如果我对其中的值进行硬编码,它确实会分裂。
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim objFSO, objInputFile, objOutputFile
Dim intLine, intFile
Dim strHeaders
Dim strInputFile, strOutputPrefix, strLine
Dim MyDate
Dim userSplit
Dim split
'strInputFile = InputBox("Enter file location")
strInputFile = "H:\VBS\domS_CUST.csv"
strOutputPrefix = strInputFile & DatePart("yyyy", Now) & "-" & DatePart("m", Now) & "-" & DatePart("d", Now)
intFile = 1
intLine = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(strInputFile, ForReading)
If (objInputFile.AtEndOfStream = True) Then
' The file is empty
WScript.Quit 1
End If
strHeaders = objInputFile.ReadLine
userSplit = InputBox("Enter when you want to split")
Do While (objInputFile.AtEndOfStream = False)
split = userSplit
strLine = objInputFile.ReadLine
If (intLine <= 0) Then
Set objOutputFile = objFSO.CreateTextFile(strOutputPrefix & "_" & intFile & ".csv", True)
objOutputFile.WriteLine strHeaders
intLine = 1
End If
objOutputFile.WriteLine strLine
If (intLine >= split) Then
objOutputFile.Close
Set objOutputFile = Nothing
intFile = intFile + 1
intLine = 0
Else
intLine = intLine + 1
End If
Loop
输入是这一行:
userSplit = InputBox("Enter when you want to split")
而且我似乎无法将其拆分为这个值,任何帮助将不胜感激!