Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for ascii2uc.vbs

(view source code of ascii2uc.vbs as plain text)

  1. Option Explicit
  2. On Error Resume Next
  3.  
  4. Const ForReading = 1, ForWriting = 2, ForAppending = 8
  5. Dim objFSO, objTgtFile, objSrcFile, strAscii, strTgtFile, strSrcFile, strMsg
  6.  
  7. strSrcFile = WScript.Arguments.UnNamed(0)
  8. strTgtFile = WScript.Arguments.UnNamed(1)
  9. strAscii   = ""
  10. strMsg     = ""
  11.  
  12. ' Check command line arguments
  13. If WScript.Arguments.UnNamed.Count <> 2 Then Syntax( )
  14. If WScript.Arguments.Named.Count    > 0 Then Syntax( )
  15.  
  16. ' Create File System Object and check if source and target files exist
  17. Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  18. If Err Then ShowError( )
  19. If objFSO.FileExists( strSrcFile ) = False Then
  20. 	strMsg = vbCrLf & "File not found: " & strSrcFile & vbCrLf
  21. 	Syntax( )
  22. End If
  23. If objFSO.FileExists( strTgtFile ) = True Then
  24. 	strMsg = vbCrLf & "File exists: " & strTgtFile & vbCrLf
  25. 	Syntax( )
  26. End If
  27.  
  28. ' Read ASCII file and store content in variable
  29. Set objSrcFile = objFSO.OpenTextFile( strSrcFile, ForReading )
  30. If Err Then ShowError( )
  31. While Not objSrcFile.AtEndOfStream
  32. 	strAscii = strAscii & objSrcFile.ReadLine & vbCrLf
  33. WEnd
  34. objSrcFile.Close
  35.  
  36. ' Create new Unicode text file
  37. Set objTgtFile = objFSO.CreateTextFile( strTgtFile, True, True )
  38. If Err Then ShowError( )
  39. objTgtFile.Write strAscii
  40. objTgtFile.Close
  41.  
  42.  
  43. Sub ShowError()
  44. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  45. 	         Err.Description & vbCrLf & vbCrLf
  46. 	Syntax
  47. End Sub
  48.  
  49.  
  50. Sub Syntax( )
  51. 	strMsg = strMsg & vbCrLf _
  52. 	       & "ASCII2UC.vbs,  Version 1.00" & vbCrLf _
  53. 	       & "Convert text from ASCII to Unicode" & vbCrLf & vbCrLf _
  54. 	       & "Usage:  CSCRIPT  ASCII2UC.VBS  ascii_file  unicode_file" _
  55. 	       & vbCrLf & vbCrLf _
  56. 	       & "Where:  " & Chr(34) & "ascii_file" & Chr(34) _
  57. 	       & "   is the source text file, which must be in ASCII format" _
  58. 	       & vbCrLf _
  59. 	       & "        " & Chr(34) & "unicode_file" & Chr(34) _
  60. 	       & " is the name of the target file, which will be in Unicode" _
  61. 	       & vbCrLf & vbCrLf _
  62. 	       & "Written by Rob van der Woude" & vbCrLf _
  63. 	       & "http://www.robvanderwoude.com" & vbCrLf
  64. 	WScript.Echo strMsg
  65. 	WScript.Quit(1)
  66. End Sub
  67.  

page last modified: 2024-04-16; loaded in 0.0083 seconds