Advertisement
Guest User

batch for execution

a guest
Oct 3rd, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1.  
  2. @ ECHO OFF
  3. setlocal enabledelayedexpansion
  4. REM Usage, pass in file types you want to execute command line.
  5. REM or set the following variable to define the default types to be executed
  6. REM e.g. set filtypes=exe bat msi
  7. set filetypes=exe bat msi
  8. REM Works with file and folder names that include spaces
  9. REM Easiest way to use this is probably to set filetypes to a default
  10. REM Copy the script to the folder with whatever you want executed
  11. REM double click the batch file
  12.  
  13. REM Switch to whatever drive letter this is being run from (e.g. "c:")
  14. %~d1
  15. REM change in to the directory of where this script is being run
  16. cd "%~dp0"
  17.  
  18. set argCount=0
  19. set regexes=
  20. REM count how many arguments were passed in
  21. for %%x in (%*) do Set /A argCount+=1
  22. REM if arguments were passed in, overwrite the default types with the passed in ones
  23. if %argCount% gtr 0 set filetypes=%*
  24.  
  25. REM put together full expressions to be used to search for the files
  26. REM e.g. "C:\tmp\*.exe C:\tmp\*.bat C:\tmp\*.msi"
  27. for %%r in (%filetypes%) do (
  28. set regexes=!regexes! *.%%r
  29.  
  30. )
  31.  
  32. REM go through all of the regular expressions
  33. REM use them to search the current directory for matching files
  34. REM (2 if conditional to cover commandline run vs gui run)
  35. REM then execute those files as long as it is not this file
  36. echo %regexes%
  37. for %%f in (%regexes%) do (
  38. if not %%f == %0 (
  39. if not "%~dp0%%f" == %0 (
  40. echo ********************************
  41. echo executing %%f
  42. call "%%f"
  43. )
  44. )
  45. )
  46.  
  47. pause
  48. @ ECHO ON
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement