Advertisement
nwarden

DREP.CMD > DERP_results.txt

May 6th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.38 KB | None | 0 0
  1. @echo off
  2. REM ###############################################################################################
  3. REM # DREP.CMD
  4. REM # v.2016.05.06-e
  5. REM # tested on Windows 10
  6. REM # by Nigel Warden
  7. REM #
  8. REM # can double-click or run from the command line with one
  9. REM #                       C:\>drep aNy sTriNg y0u wAnT to SeArcH
  10. REM # searches the contents of text files for the specified string, within the current directory
  11. REM # returns filenames to the console, mirroring the output to DERP_results_[date]_[time].txt
  12. REM # rings the bell and opens txt in notepad when finished
  13. REM ###############################################################################################
  14. setlocal ENABLEDELAYEDEXPANSION
  15. set count=0
  16. set found=0
  17. set lines=0
  18. set tym=%time:~0,-3%
  19. set tym=%tym::=%
  20. set tym=%tym: =%
  21. set tym=%date%_%tym%
  22. set ofile=DERP_results_%tym%.txt
  23.  
  24. REM ####### a space-delimited list of file extensions to search (wildcards allowed)
  25. set filetypes=*.php *.*htm* *.ini .htaccess
  26.  
  27. :AGAIN
  28. cls
  29. if "%1"=="" (
  30.    echo.
  31.    echo.
  32.    set /P ask=SEARCH [%filetypes%] FILES FOR TEXT:
  33. ) else (
  34.    set ask=%1
  35. )
  36. if "%ask%"=="" ( goto AGAIN )
  37. cls
  38.  
  39. echo.>>%ofile% && more +!lines! %ofile% && set /A lines=!lines!+1
  40. echo ...searching [%filetypes%] files for: "%ask%">>%ofile% && more +!lines! %ofile% && set /A lines=!lines!+1
  41. echo.>>%ofile% && more +!lines! %ofile% && set /A lines=!lines!+1
  42. echo ===[ %date% %time% ]=============================================>>%ofile% && more +!lines! %ofile% && set /A lines=!lines!+1
  43. echo.>>%ofile% && more +!lines! %ofile% && set /A lines=!lines!+1
  44.  
  45. for /f "delims=" %%i in ('dir /b /s %filetypes%') DO (
  46.    findstr /M /I "%ask%" "%%i" && set /A found=!found!+1 && echo %%i>>%ofile% && set /A lines=!lines!+1
  47.    set /A count=!count!+1
  48. )
  49.  
  50. echo.>>%ofile% && more +!lines! %ofile% && set /A lines=!lines!+1
  51. echo ===[ %date% %time% ]=============================================>>%ofile% && more +!lines! %ofile% && set /A lines=!lines!+1
  52. echo.>>%ofile% && more +!lines! %ofile% && set /A lines=!lines!+1
  53. REM ####### "rings the bell" ... must copypasta the bell character yourself. pastebin doesn't support it. put them after the /p=
  54. echo | set /p=
  55. ping -n 2 127.0.0.1>nul
  56. echo | set /p=
  57. ping -n 2 127.0.0.1>nul
  58. echo | set /p=
  59. echo DONE. [found !found! in %count% files]>>%ofile% && more +!lines! %ofile%
  60.  
  61. notepad %ofile%
  62. waitfor %RANDOM%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement