Advertisement
RyzaJr

[BATCH] Find

Dec 31st, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.28 KB | None | 0 0
  1. ::This batch script attempts to find a string in files within a directory using your query.
  2.  
  3. @echo off
  4.  
  5. :start
  6.  
  7. set "TEST=%~1"
  8.  
  9. if not "%TEST%"=="" (
  10.     set "DIRECTORY=%~1"
  11.     goto test
  12. ) else (
  13.     echo Enter the folder you would like to search in below.
  14.     echo (Note: Subfolders will be searched as well.^)
  15.     echo.
  16.     set /p DIRECTORY= "Directory: "
  17. )
  18.  
  19. :: ======================================================
  20.  
  21. if "%DIRECTORY%"=="" (goto none) else (goto test)
  22.  
  23. :none
  24. cls
  25. echo No folder selected.
  26. echo.
  27. echo Restarting search...
  28. timeout /t 3 /nobreak > nul
  29. cls
  30. goto start
  31.  
  32. :test
  33. if exist "%DIRECTORY%" (cls & goto find)
  34. cls
  35. echo That folder does not exist.
  36. echo.
  37. echo Restarting search...
  38. timeout /t 3 /nobreak > nul
  39. set "DIRECTORY="
  40. cls
  41. goto start
  42.  
  43. :: ======================================================
  44.  
  45. :find
  46. echo A search will now be performed within the following folder:
  47. echo "%DIRECTORY%"
  48. echo.
  49. echo ------------------------------------------------------------------
  50. echo.
  51. echo Find what string of text?
  52. echo.
  53. set /p "FIND=Find: "
  54. cls
  55.  
  56. findstr /s /i /m /c:"%FIND%" "%DIRECTORY%\*.*"
  57.  
  58. :: ======================================================
  59.  
  60. echo.
  61. echo Search completed.
  62. timeout /t 2 /nobreak > nul
  63. echo.
  64. pause
  65. cls
  66. set "DIRECTORY="
  67. goto start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement