'######################################################## '### Writes the content of string into a file ### '### ### '### (c) Dirk Pelzer 2004 ### '######################################################## Option Explicit Dim strFileName Dim strContent Dim intRet strFileName = "C:\Temp\Test.txt" intRet = ReadFile(strFileName, strContent) Select Case intRet Case 0 wscript.echo "File " & strFileName & " read successfully." wscript.echo "Content:" & vbCRLF & strContent wscript.quit (0) Case 1 wscript.echo "Error: Specified file does not exist." wscript.echo "Script aborted." wscript.quit(1) Case 2 wscript.echo "Error: Specified file was empty." wscript.echo "Script aborted." wscript.quit(1) Case Else wscript.echo "Unknown error. Script aborted." wscript.quit (1) End Select '************************************************* ' ReadFile '************************************************* Function ReadFile(strFileName, strReadBuffer) ' Returns the content of a specified file in strReadBuffer ' ReadFile = 0: success ' ReadFile = 1: specified file does not exist ' ReadFile = 2: the file was empty Const ForReading = 1, ForWriting = 2 Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") If NOT (fso.FileExists(strFileName)) Then ReadFile = 1 'Specified file does nor exist Set fso = Nothing Exit Function End If Set f = fso.OpenTextFile(strFileName, ForReading) strReadBuffer = f.ReadAll if len(strReadBuffer)> 0 Then ReadFile = 0 'File read successfully Else ReadFile = 2 'File was empty End if Set f = Nothing Set fso = Nothing End Function