Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for a2u.bat

(view source code of a2u.bat as plain text)

  1. @ECHO OFF
  2. :: A2U
  3. :: AUTHOR: CARLOS M.
  4. :: DATE:   10-MAY-2011
  5.  
  6. SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
  7. SET ASCIIFile=%~f1
  8. IF NOT DEFINED ASCIIFile GOTO :_A2UHLP_
  9. IF "%~1"=="/?" GOTO :_A2UHLP_
  10. IF /I "%~1"=="-H" GOTO :_A2UHLP_
  11.  
  12. IF NOT EXIST "!ASCIIFile!" (
  13. 	ECHO Error: file "!ASCIIFile!" not exist
  14. 	ENDLOCAL
  15. 	EXIT /B 1
  16. )
  17. TYPE "!ASCIIFile!" >NUL 2>&1 || (
  18. 	ECHO Error: could not read file "!ASCIIFile!"
  19. 	ENDLOCAL
  20. 	EXIT /B 1
  21. )
  22.  
  23. IF /I "%~f0"=="%~f1" (
  24. 	ECHO Error: could not convert itself
  25. 	ENDLOCAL
  26. 	EXIT /B 1
  27. )
  28.  
  29. SET UnicodeFile=%~f2
  30. IF NOT DEFINED UnicodeFile SET UnicodeFile=%~f1
  31. IF EXIST "!UnicodeFile!\" (
  32. 	ECHO Error: could not write to file "!UnicodeFile!"
  33. 	ENDLOCAL
  34. 	EXIT /B 1
  35. )
  36.  
  37. IF /I "%~f0"=="%~f2" (
  38. 	ECHO Error: could not overwrite itself
  39. 	ENDLOCAL
  40. 	EXIT /B 1
  41. )
  42.  
  43. Pushd "!TEMP!"
  44. :_A2U_TMP
  45. SET TempFile=_%random%_.t_
  46. IF EXIST "!TempFile!" GOTO :_A2U_TMP
  47. FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%A) DO SET CodePage=%%B
  48. CHCP 1252 >NUL
  49. CMD.EXE /D /A /C (SET/P=ÿþ)<NUL > "!TempFile!" 2>NUL
  50. CHCP %CodePage% >NUL
  51. CMD.EXE /D /U /C TYPE "!ASCIIFile!" >> "!TEMP!\!TempFile!"
  52. Popd
  53.  
  54. COPY /B /Y /V "!TEMP!\!TempFile!" "!UnicodeFile!" >NUL 2>&1 || (
  55. 	DEL /F /Q /A "!TEMP!\!TempFile!" >NUL 2>&1
  56. 	ECHO Error: could not write to file "!UnicodeFile!"
  57. 	ENDLOCAL
  58. 	EXIT /B 1
  59. )
  60. DEL /F /Q /A "!TEMP!\!TempFile!" >NUL 2>&1
  61. EXIT /B 0
  62.  
  63. :_A2UHLP_
  64. ECHO %~nx0 : Convert ascii text file to unicode text file.
  65. ECHO Usage: %~nx0 source.txt [destination.txt]
  66. ECHO If you don't specify a destination %~nx0 will overwrite source.txt
  67. ENDLOCAL
  68. EXIT /B 1
  69.  

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