Home
Manage Your Code
Snippet: List and combine all text files in a folder (VBScript)
Title: List and combine all text files in a folder Language: VBScript
Description: VBScript code to combine all text ( sql ) files in one file Views: 3984
Author: chirag shah Date Added: 5/7/2009
Copy Code  
1On Error Resume Next  
2Dim fso, folder, files, NewsFile,sFolder, objTextFile
3Const ForReading = 1
4
5Set fso = CreateObject("Scripting.FileSystemObject")
6Set objOutputFile = fso.CreateTextFile("EMDAllStoredProcedures.sql")
7currentPath  = Replace(Wscript.ScriptFullName, "\" & Wscript.ScriptName, "")
8
9sFolder = Wscript.Arguments.Item(0)  
10	If sFolder = "" Then      
11		sFolder =  currentPath & "\Stored Procedures"
12		'Wscript.Echo sFolder
13		'Wscript.Quit  
14	End If
15
16Set files = fso.GetFolder(sFolder).Files
17Echo file.Count
18For each folderIdx In files    
19	if lcase(objFSO.getExtensionName(file.path))="txt" then
20		Set objTextFile = fso.OpenTextFile(folderIdx.path, ForReading) 
21		strText = objTextFile.ReadAll
22		objTextFile.Close
23		objOutputFile.WriteLine strText
24	End if
25Next  
26objOutputFile.Close
27