Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for owner.bat

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

  1. @ECHO OFF
  2. ECHO.
  3.  
  4. :: Check Windows version
  5. VER | FIND /V "Windows 2000" >NUL
  6. IF NOT ERRORLEVEL 1 GOTO Start
  7. VER | FIND /V "Windows XP" >NUL
  8. IF ERRORLEVEL 1 GOTO WrongVer
  9.  
  10. :Start
  11. SETLOCAL
  12.  
  13. :: Check command line parameter
  14. SET OwnedFile=%1
  15. IF NOT DEFINED OwnedFile   GOTO Syntax
  16. SET OwnedFile=%OwnedFile:"=%
  17. IF "%OwnedFile%"=="/?"     GOTO Syntax
  18. IF NOT EXIST "%OwnedFile%" GOTO Syntax
  19. IF EXIST "%OwnedFile%\"    GOTO Syntax
  20.  
  21. :: Does filespec contain wildcards?
  22. ECHO.%OwnedFile% | FIND "?" >NUL
  23. IF NOT ERRORLEVEL 1 GOTO Multiple
  24. ECHO.%OwnedFile% | FIND "*" >NUL
  25. IF NOT ERRORLEVEL 1 GOTO Multiple
  26.  
  27. :: Show owner of specified single file; display owner only
  28. FOR /F "skip=5 tokens=4 delims= " %%A IN ('DIR/A-D/Q "%OwnedFile%" ^| FIND /V "(s)"') DO ECHO.%%A
  29. ENDLOCAL
  30. GOTO End
  31.  
  32. :Multiple
  33. :: Show owner of specified files; display owner and file name
  34. FOR /F "skip=5 tokens=4* delims= " %%A IN ('DIR/A-D/Q "%OwnedFile%" ^| FIND /V "(s)"') DO ECHO.%%A	%%B
  35. ENDLOCAL
  36. GOTO End
  37.  
  38. :WrongVer
  39. ECHO This batch file requires Windows 2000 or a later version
  40. GOTO End
  41.  
  42. :Syntax
  43. ECHO Owner.bat,  Version 1.00 for Windows 2000 / XP
  44. ECHO Show the owner^(s^) of specified file^(s^)
  45. ECHO.
  46. ECHO Usage:  %~n0  ^<filespec^>
  47. ECHO.
  48. ECHO ^<filespec^> should NOT be a directory name.
  49. ECHO If ^<filespec^> contains wildcards, both the owners and
  50. ECHO the file names will be displayed ^(tab delimited^)
  51. ECHO.
  52. ECHO Written by Rob van der Woude
  53. ECHO http://www.robvanderwoude.com
  54.  
  55. :End
  56.  

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