Advertisement
T3RRYT3RR0R

LogFileFunction

Dec 30th, 2019
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.08 KB | None | 0 0
  1. REM See Also https://pastebin.com/auWb4ELX for a menu based file Logger
  2.  
  3. @ECHO OFF
  4. SETLOCAL EnableDelayedExpansion
  5. Set Val=0
  6. Set Found=0
  7. Set Home_Dir=%windir%\system32
  8. Set Prog_Dir=%~dp0
  9. if exist "files.txt" (
  10. DEL /Q files.txt
  11. )
  12.  
  13. MODE CON: cols=150 lines=30
  14.  
  15. ::: Add remove extensions to be searched to suit needs
  16.  
  17. Set "ext=com" && CALL :process
  18. Set "ext=dll" && CALL :process
  19.  
  20. REM ::: Display Completion Statement
  21.  
  22. ECHO 
  23. ECHO  Logging Complete. !Found! Files found out of !Val! Files Searched
  24. ECHO 
  25.  
  26. REM ::: Open the Log
  27.  
  28. START notepad.exe %Prog_Dir%files.txt
  29. pause > nul
  30. exit
  31.  
  32. REM ::: Recursive option for Substitution with CD .. FOR %%a IN ..
  33. REM ::: FOR /R "%Home_Dir%" %%a IN (*.%ext%) DO (
  34.  
  35.  
  36. REM ::: Use For Loop to Generate array of File Information, Call extFilter to Sort Desired Files.
  37.  
  38. :process
  39. CD %Home_Dir%
  40. FOR %%a IN (*.%ext%) DO (
  41.         Set /a Val+=1
  42.         Set name[!val!]=%%~na
  43.         Set EXT[!val!]=%%~xa
  44.         Set location[!val!]=%%~dpa
  45.         CALL :extFilter
  46. )
  47. GOTO :EOF
  48.  
  49. REM ::: Call Filter by Filetype.
  50. REM ::: Adjust Conditions to suit Needs.
  51.  
  52.  
  53. :extFilter
  54. IF "!EXT[%val%]!"==".com" CALL :Filter_com
  55. IF "!EXT[%val%]!"==".dll" CALL :Filter_dll
  56. GOTO :EOF
  57.  
  58. REM ::: Test for Specific Letter in Specific Position Of filename String, Log if True.
  59.  
  60. :Filter_dll
  61. Set "testletter=!name[%val%]!"
  62. Set testletter=%testletter:~1,1%
  63.             IF /I "!testletter!"=="i" (
  64.         Set /a Found+=1
  65.         ECHO  Logging File... !location[%Val%]! !Val! Files Searched
  66.         ECHO  Found !Found! Files
  67.         ECHO  Last File Logged: !name[%val%]!!EXT[%val%]!
  68.         ECHO !location[%val%]!!name[%val%]!!EXT[%val%]!>>%Prog_Dir%files.txt
  69.     ) else (
  70.     ECHO  Searching... !location[%Val%]! !Val! Files Searched
  71. )
  72.  
  73. GOTO :EOF
  74.  
  75. REM ::: Test Filename for Specific length with use of 'strlen' sub-function, Log if True.
  76.  
  77. :Filter_com
  78. Call :strlen result !name[%val%]!
  79.             IF !result!==4 (
  80.         Set /a Found+=1
  81.         ECHO  Logging File... !location[%Val%]! !Val! Files Searched
  82.         ECHO  Found !Found! Files
  83.         ECHO  Last File Logged: !name[%val%]!!EXT[%val%]!
  84.         ECHO !location[%val%]!!name[%val%]!!EXT[%val%]!>>%Prog_Dir%files.txt
  85.     ) else (
  86.     ECHO  Searching... !location[%Val%]! !Val! Files Searched
  87. )
  88.  
  89. GOTO :EOF
  90.  
  91. REM ::: Sub function using For loop to test a String against itself and Determine length of string.
  92.  
  93. REM ********* function thanks to Jeb https://stackoverflow.com/users/463115/jeb *****************************
  94. :strlen <resultVar> <stringVar>
  95. set tmp=%~2
  96. If defined tmp (
  97.         set "len=1"
  98.         for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  99.             if "!tmp:~%%P,1!" NEQ "" (
  100.                 set /a "len+=%%P"
  101.                 set "tmp=!tmp:~%%P!"
  102.             )
  103.         )
  104.     ) ELSE (
  105.         set len=0
  106. )
  107. (
  108.     set "%~1=%len%"
  109.     exit /b
  110. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement