Hi All- I need to write a VB script which can append all the text files available within a folder and finally create a single source file.For example if there are 100 text files within the Source Folder,script should create a single source file by combining all the 100 text files.This is the code I am using.
On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder, objTextFile
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = fso.CreateTextFile("FinalSource.txt")
currentPath = Replace(Wscript.ScriptFullName, "\" & Wscript.ScriptName, "")
sFolder = Wscript.Arguments.Item(0)
If sFolder = "" Then
sFolder = currentPath & "\Source"
'Wscript.Echo sFolder
'Wscript.Quit
End If
Set files = fso.GetFolder(sFolder).Files
Echo file.Count
For each folderIdx In files
if lcase(objFSO.getExtensionName(file.path))="txt" then
Set objTextFile = fspenTextFile(folderIdx.path, ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText
End if
Next
objOutputFile.Close
This code working fine in creating single file.There are two headers in each text file one for Field name and other is the field data type.But the header is repeating each time means in the final text file header appeared 100 times.
Can someone please help me tweaking above code just to append data without header information.The source file should contain only one header i.e. the field name.
Here is the SAMPLE DATA
file-1
"callManagerId","callId","CallIdentifier","dateTime"
INTEGER,INTEGER,INTEGER,INTEGER
1,1,458593,45640066
1,2,794399,45640053
1,2,794393,45640037
1,4,747779,45639792
file-2
"callManagerId","callId","CallIdentifier","dateTime"
INTEGER,INTEGER,INTEGER,INTEGER
1,9,4585989,45640000
1,9,494396,45640053
1,5,394390,45640037
1,3,747779,45639792
Final Data Should Be
"callManagerId","callId","CallIdentifier","dateTime"
1,1,458593,45640066
1,2,794399,45640053
1,2,794393,45640037
1,4,747779,45639792
1,9,4585989,45640000
1,9,494396,45640053
1,5,394390,45640037
1,3,747779,45639792
Thanks.
On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder, objTextFile
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = fso.CreateTextFile("FinalSource.txt")
currentPath = Replace(Wscript.ScriptFullName, "\" & Wscript.ScriptName, "")
sFolder = Wscript.Arguments.Item(0)
If sFolder = "" Then
sFolder = currentPath & "\Source"
'Wscript.Echo sFolder
'Wscript.Quit
End If
Set files = fso.GetFolder(sFolder).Files
Echo file.Count
For each folderIdx In files
if lcase(objFSO.getExtensionName(file.path))="txt" then
Set objTextFile = fspenTextFile(folderIdx.path, ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText
End if
Next
objOutputFile.Close
This code working fine in creating single file.There are two headers in each text file one for Field name and other is the field data type.But the header is repeating each time means in the final text file header appeared 100 times.
Can someone please help me tweaking above code just to append data without header information.The source file should contain only one header i.e. the field name.
Here is the SAMPLE DATA
file-1
"callManagerId","callId","CallIdentifier","dateTime"
INTEGER,INTEGER,INTEGER,INTEGER
1,1,458593,45640066
1,2,794399,45640053
1,2,794393,45640037
1,4,747779,45639792
file-2
"callManagerId","callId","CallIdentifier","dateTime"
INTEGER,INTEGER,INTEGER,INTEGER
1,9,4585989,45640000
1,9,494396,45640053
1,5,394390,45640037
1,3,747779,45639792
Final Data Should Be
"callManagerId","callId","CallIdentifier","dateTime"
1,1,458593,45640066
1,2,794399,45640053
1,2,794393,45640037
1,4,747779,45639792
1,9,4585989,45640000
1,9,494396,45640053
1,5,394390,45640037
1,3,747779,45639792
Thanks.