Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for shortext.bat

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

  1. @ECHO OFF
  2. IF NOT [%OS%]==[Windows_NT] GOTO Syntax
  3. IF NOT [%1]==[] IF NOT [%1]==[0] IF NOT [%1]==[1] GOTO Syntax
  4.  
  5. SETLOCAL
  6.  
  7. REGEDIT /E %Temp%.\ShortExt.reg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem"
  8. FOR /F "tokens=2 delims=:" %%A IN ('TYPE %Temp%.\ShortExt.reg ^| FIND "Win95TruncatedExtensions"') DO SET /A W95TruncExt=%%A
  9. DEL %Temp%.\ShortExt.reg
  10.  
  11. CALL :FuncDescr
  12. CALL :Display %W95TruncExt% Current
  13. ECHO Type %~n0 /? for online help
  14.  
  15. IF [%1]==[] GOTO End
  16. > %Temp%.\_ShortExt.reg ECHO REGEDIT4
  17. >>%Temp%.\_ShortExt.reg ECHO.
  18. >>%Temp%.\_ShortExt.reg ECHO [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
  19. >>%Temp%.\_ShortExt.reg ECHO "Win95TruncatedExtensions"=dword:0000000%1
  20. >>%Temp%.\_ShortExt.reg ECHO.
  21. START /WAIT REGEDIT /S %Temp%.\_ShortExt.reg
  22. DEL %Temp%.\_ShortExt.reg
  23.  
  24. REGEDIT /E %Temp%.\ShortExt.reg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem"
  25. FOR /F "tokens=2 delims=:" %%A IN ('TYPE %Temp%.\ShortExt.reg ^| FIND "Win95TruncatedExtensions"') DO SET /A W95TruncExt=%%A
  26. DEL %Temp%.\ShortExt.reg
  27. CALL :Display %W95TruncExt% New
  28.  
  29. ENDLOCAL
  30. GOTO End
  31.  
  32. :Display
  33. ECHO.
  34. ECHO %2 value:
  35. ECHO.
  36. ECHO     [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
  37. ECHO     Win95TruncatedExtensions=%1
  38. ECHO.
  39. IF [%1]==[0] (ECHO Extension truncation is disabled) ELSE (ECHO Extension truncation is enabled)
  40. ECHO.
  41. GOTO:EOF
  42.  
  43. :FuncDescr
  44. ECHO.
  45. ECHO By default, Windows NT and 2000 evaluate file extensions on the first
  46. ECHO three characters: "filename.html" is actually treated as "filename.htm".
  47. ECHO Therefore if you use a command such as "del *.htm" to delete all the
  48. ECHO ".htm" files, you will also delete all ".html" files as well.
  49. ECHO This behaviour will be referred to as "extension truncation".
  50. ECHO Extension truncation can be disabled by modifying the registry, which
  51. ECHO is exactly what this batch file can do for you.
  52. GOTO:EOF
  53.  
  54. :Syntax
  55. ECHO.
  56. ECHO ShortExt.bat,  Version 1.00 for Windows NT 4 / 2000
  57. ECHO Display or modify the Win95TruncatedExtensions registry entry
  58. CALL :FuncDescr
  59. ECHO.
  60. ECHO Usage:  %~n0  [ 0 ^| 1 ]
  61. ECHO.
  62. ECHO Without command line parameters, the current value will be displayed.
  63. ECHO Command line parameter 0 will disable extension truncation.
  64. ECHO Command line parameter 1 will reenable extension truncation again.
  65. ECHO.
  66. ECHO Written by Rob van der Woude
  67. ECHO http://www.robvanderwoude.com
  68. ECHO Based on a tip from Windows Registry Guide
  69. ECHO http://registry.winguides.com
  70. ECHO.
  71.  
  72. :End
  73.  

page last uploaded: 2017-07-06, 12:37