Guest User

updated with sub dirs

a guest
Oct 3rd, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 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. REM first loop handles the base directory
  37. REM second loop handles sub directories
  38. for %%f in (%regexes%) do (
  39. if not %%f == %0 (
  40. if not "%~dp0%%f" == %0 (
  41. echo ********************************
  42. echo executing %%f
  43. call "%%f"
  44. )
  45. )
  46. )
  47.  
  48. REM updated to do this for all the subfolders as well
  49. for /D %%d in (*) do (
  50. for %%f in (%regexes%) do (
  51. cd %%d
  52. if not %%f == %0 (
  53. if not "%~dp0%%f" == %0 (
  54. echo ********************************
  55. echo executing %%f
  56. call "%%f"
  57. )
  58. )
  59. cd %~dp0
  60. )
  61. )
  62. pause
  63. @ ECHO ON
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment