1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
On Error Resume Next
Const verStr = "v0.13" Const ForReading = 1 Dim stdFlag Dim lines Dim strRead Dim filePath Dim objFSO Dim objFile
stdFlag=True lines = CInt(WScript.Arguments(0)) If lines<1 And Len(WScript.Arguments(0))>1 Then lines =10 filePath =WScript.Arguments(0) stdFlag =False End If Err.Clear
If WScript.Arguments.length>1 And Len(filePath)<1 Then filePath=WScript.Arguments(1) stdFlag =False End If
If stdFlag Then strRead=WScript.StdIn.ReadLine
If Len(strRead)>0 Then stdFlag=True WScript.Echo strRead lines = lines-1 End If If Error<>0 Then stdFlag =False Err.Clear
If stdFlag Then Do Until WScript.stdin.AtEndOfStream Or lines<1 Or Err.Number<>0 strContents = WScript.stdin.ReadLine WScript.Echo strContents lines = lines-1 Loop Else Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(filePath) Then Set objFile = objFSO.GetFile(filePath) If objFile.Size > 0 Then Set objReadFile = objFSO.OpenTextFile(filePath, ForReading) Do Until objreadfile.AtEndOfStream Or lines<1 Or Err.Number<>0 strContents = objReadFile.ReadLine Wscript.Echo strContents lines = lines-1 Loop objReadFile.Close Else Wscript.Echo "The file is empty." End If Else Wscript.Echo "File (" & filePath & ") is not found." End If End If
|