Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for shortcut.bat

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

  1. @ECHO OFF
  2. :: Check OS version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. :: Keep variables local
  6. SETLOCAL
  7.  
  8. :: Check command line parameters
  9. IF "%~1"=="" GOTO Syntax
  10. IF NOT EXIST "%~1" GOTO Syntax
  11.  
  12. :: Check if multiple files were specified
  13. FOR /F %%A IN ('DIR /A-D/B/ON/P/-P "%~1" ^| FIND /C "."') DO SET NUMFILES=%%A
  14. IF "%NUMFILES%"=="1" GOTO ExtCheck
  15. FOR %%A IN ("%~1") DO CALL %0 "%%~A"
  16. GOTO End
  17.  
  18. :ExtCheck
  19. :: If a single file is specified, the extension should be ".LNK"
  20. IF /I NOT "%~x1"==".LNK" GOTO Syntax
  21.  
  22. :: Find the shortcut's path
  23. FOR /F "tokens=*" %%A IN ('TYPE "%~1" ^| FIND "\"') DO CALL :Parse "%%~A"
  24. ECHO.
  25. IF "%LINKPATH%"=="" GOTO DispUNC
  26. ECHO Fully qualified path of "%~nx1":
  27. ECHO.    %LINKPATH%
  28. ECHO.
  29. :DispUNC
  30. IF "%LINKUNC%"=="" GOTO DispNone
  31. ECHO UNC of "%~nx1":
  32. ECHO.    %LINKUNC%
  33. ECHO.
  34. :DispNone
  35. IF NOT "%LINKUNC%"=="" GOTO End
  36. IF NOT "%LINKPATH%"=="" GOTO End
  37. ECHO No path found!
  38. ECHO.
  39. GOTO End
  40.  
  41. :Parse
  42. SET LINE=%~1
  43. :: Remove leading space introduced by previous line (NT 4 only)
  44. VER | FIND "Windows NT" >NUL
  45. IF NOT ERRORLEVEL 1 IF NOT "%LINE%"=="" SET LINE=%LINE:~1%
  46. :: Skip this line if empty
  47. IF "%LINE%"=="" GOTO:EOF
  48. :: Skip lines beginning with "#"
  49. IF "%LINE:~0,1%"=="#" GOTO:EOF
  50. :: Store UNC of share
  51. IF "%LINE:~0,2%"=="\\" (SET LINKUNC=%LINE%&GOTO:EOF)
  52. :: Store drive
  53. IF "%LINE:~1,2%"==":\" (SET LINKPATH=%LINE%&GOTO:EOF)
  54. :: Skip this line if it starts with "\"
  55. IF "%LINE:~0,1%"=="\" GOTO:EOF
  56. :: Add relative path to UNC and to drive letter
  57. IF NOT "%LINKPATH%"=="" SET LINKPATH=%LINKPATH%%LINE%
  58. IF NOT "%LINKUNC%"==""  SET LINKUNC=%LINKUNC%\%LINE%
  59. GOTO:EOF
  60.  
  61. :Syntax
  62. ECHO.
  63. ECHO SHORTCUT.BAT,  Version 2.10 for Windows NT 4 and later
  64. IF     "%OS%"=="Windows_NT" ECHO Shows the fully qualified ^(UNC^) path the specified shortcut file points to.
  65. IF NOT "%OS%"=="Windows_NT" ECHO Shows the fully qualified (UNC) path the specified shortcut file points to.
  66. ECHO.
  67. ECHO Usage:  SHORTCUT  shortcut_filespec
  68. ECHO.
  69. ECHO Wildcards are allowed in the shortcut filespec.
  70. ECHO Use double quotes if the shortcut filespec contains spaces or ampersands.
  71. ECHO.
  72. ECHO Written by Rob van der Woude
  73. ECHO http://www.robvanderwoude.com
  74.  
  75. :End
  76. IF "%OS%"=="Windows_NT" ENDLOCAL
  77.  

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