Option Explicit
Const C_DATA_DIR = ".\" ' "C:\Data\"
Const C_FILELIST = "filelist.txt"
Const C_SEP = "|"
Const C_SEP_FILELIST = ","
Dim objFSO, objFilelist, arrFields, strFilename, intYearColumnNumber, objFile, blnFirst, strLine, strHeader, strYear, objFileOut1, objFileOut2, colFiles
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colFiles = CreateObject("Scripting.Dictionary")
' get file name and year column number for each file to be processed
Set objFilelist = objFSO.OpenTextFile(C_FILELIST, 1, False)
While Not objFilelist.AtEndOfStream
arrFields = Split(objFilelist.ReadLine, C_SEP_FILELIST)
strFilename = arrFields(0)
intYearColumnNumber = CInt(arrFields(1))
Set objFile = objFSO.OpenTextFile(C_DATA_DIR & strFilename, 1, False)
blnFirst = True
While Not objFile.AtEndOfStream
strLine = objFile.ReadLine
If blnFirst Then
strHeader = strLine
blnFirst = False
Else
arrFields = Split(strLine, C_SEP)
strYear = "Non"
If UBound(arrFields) >= intYearColumnNumber-1 Then
If IsNumeric(arrFields(intYearColumnNumber-1)) Then
strYear = arrFields(intYearColumnNumber-1)
End If
End If
If Not colFiles.Exists(strYear) Then
colFiles.Add strYear, objFSO.CreateTextFile(C_DATA_DIR & strYear & "_" & strFilename, True)
colFiles(strYear).WriteLine strHeader
End If
colFiles(strYear).WriteLine strLine
End If
Wend
objFile.Close
Set objFile = Nothing
For Each strYear In colFiles
colFiles(strYear).Close
Set colFiles(strYear) = Nothing
Next
colFiles.RemoveAll
Wend
objFilelist.Close
Set objFilelist = Nothing
Set objFSO = Nothing
Set colFiles = Nothing
If CheckYear(CInt(arrFields(intYearColumnNumber-1))) Then strYear = arrFields(intYearColumnNumber-1)
and for example at the bottom of the script add:
Function CheckYear(intYear)
Select Case intYear
Case 2011, 2012, 2013:
CheckYear = True
Case Else
CheckYear = False
End Select
End Function
That last function is easy to extend when needed or even based on the current year (if that's the logic you're after).
WScript.Echo Now()
You could test one specific year easily by adjusting the CheckYear function now. If you want to take out the 'non' year processing that would be a bit more work...
objShell.Run """C:\Windows\System32\cscript.exe"" ""D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs"""
or
intErr = objShell.Run("""C:\Windows\System32\cscript.exe"" ""D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs""")
It will usually work when there is only 1 parameter because then it's just as if you're surrounding that value with parentheses instead of using them to 'bind' the parameter(s) to the function call., 0, True
back in unless the process can run in the background (same applies to line 259). The 'True' means the calling process waits for the called process to end. This is obviously necessary if another process (or the calling process) needs to work with the output generated by the previous call. Have a look here for more info: http://technet.microsoft.com/en-us/library/ee156605.aspx Const C_DATA_DIR = "D:\AppFiles\SDS\SDS_Retail_R3\Data\"
Here's my version:
Open in new window
Note: I tested with files found also in an earlier question ("2012" files). Also I saw in another question that you wanted to use a separate data directory so prepared for that.