home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / Chip_2001-06_cd1.bin / zkuste / vbasic / Data / Utility / MSISDK15.msi / WiToAnsi.vbs < prev    next >
Text File  |  2000-10-05  |  2KB  |  56 lines

  1. ' Utility to rewrite a Unicode text file as an ANSI text file
  2. ' For use with Windows Scripting Host, CScript.exe or WScript.exe
  3. ' Copyright (c) 1999-2000, Microsoft Corporation
  4. '
  5. Option Explicit
  6.  
  7. ' FileSystemObject.CreateTextFile and FileSystemObject.OpenTextFile
  8. Const OpenAsASCII   = 0 
  9. Const OpenAsUnicode = -1
  10.  
  11. ' FileSystemObject.CreateTextFile
  12. Const OverwriteIfExist = -1
  13. Const FailIfExist      = 0
  14.  
  15. ' FileSystemObject.OpenTextFile
  16. Const OpenAsDefault    = -2
  17. Const CreateIfNotExist = -1
  18. Const FailIfNotExist   = 0
  19. Const ForReading = 1
  20. Const ForWriting = 2
  21. Const ForAppending = 8
  22.  
  23. Dim argCount:argCount = Wscript.Arguments.Count
  24. If argCount > 0 Then If InStr(1, Wscript.Arguments(0), "?", vbTextCompare) > 0 Then argCount = 0
  25. If (argCount = 0) Then
  26.     Wscript.Echo "Utility to copy Unicode text file to an ANSI text file." &_
  27.         vbNewLine & "The 1st argument is the Unicode text file to read" &_
  28.         vbNewLine & "The 2nd argument is the ANSI text file to write" &_
  29.         vbNewLine & "If the 2nd argument is omitted, the Unicode file will be replaced" &_
  30.         vbNewLine &_
  31.         vbNewLine & "Copyright (C) Microsoft Corporation, 1999-2000.  All rights reserved."
  32.     Wscript.Quit 1
  33. End If
  34.  
  35. Dim inFile, outFile, inStream, outStream, inLine, FileSys, WshShell
  36. If argCount > 1 Then
  37.     outFile = Wscript.Arguments(1)
  38.     inFile  = Wscript.Arguments(0)
  39. Else
  40.     outFile = Wscript.Arguments(0)
  41.     inFile  = outFile & ".tmp"
  42.     Set WshShell = Wscript.CreateObject("Wscript.Shell")
  43.     WshShell.Run "cmd.exe /c copy " & outFile & " " & inFile, 0, True
  44. End If
  45.  
  46. Set FileSys = CreateObject("Scripting.FileSystemObject")
  47. Set inStream  = FileSys.OpenTextFile(inFile, ForReading, FailIfNotExist, OpenAsDefault)
  48. Set outStream = FileSys.CreateTextFile(outFile, OverwriteIfExist, OpenAsASCII)
  49. Do
  50.     inLine = inStream.ReadLine
  51.     outStream.WriteLine inLine
  52. Loop Until inStream.AtEndOfStream
  53. inStream.Close
  54. outStream.Close
  55. If argCount = 1 Then WshShell.Run "cmd.exe /c del " & inFile, 0
  56.