Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM See Also https://pastebin.com/auWb4ELX for a menu based file Logger
- @ECHO OFF
- SETLOCAL EnableDelayedExpansion
- Set Val=0
- Set Found=0
- Set Home_Dir=%windir%\system32
- Set Prog_Dir=%~dp0
- if exist "files.txt" (
- DEL /Q files.txt
- )
- MODE CON: cols=150 lines=30
- ::: Add remove extensions to be searched to suit needs
- Set "ext=com" && CALL :process
- Set "ext=dll" && CALL :process
- REM ::: Display Completion Statement
- ECHO [1;1H[K[33m[K
- ECHO [2;1H[K[36m[7m[K Logging Complete. [37m!Found![36m Files found out of [37m!Val![36m Files Searched
- ECHO [3;1H[K[33m[K
- REM ::: Open the Log
- START notepad.exe %Prog_Dir%files.txt
- pause > nul
- exit
- REM ::: Recursive option for Substitution with CD .. FOR %%a IN ..
- REM ::: FOR /R "%Home_Dir%" %%a IN (*.%ext%) DO (
- REM ::: Use For Loop to Generate array of File Information, Call extFilter to Sort Desired Files.
- :process
- CD %Home_Dir%
- FOR %%a IN (*.%ext%) DO (
- Set /a Val+=1
- Set name[!val!]=%%~na
- Set EXT[!val!]=%%~xa
- Set location[!val!]=%%~dpa
- CALL :extFilter
- )
- GOTO :EOF
- REM ::: Call Filter by Filetype.
- REM ::: Adjust Conditions to suit Needs.
- :extFilter
- IF "!EXT[%val%]!"==".com" CALL :Filter_com
- IF "!EXT[%val%]!"==".dll" CALL :Filter_dll
- GOTO :EOF
- REM ::: Test for Specific Letter in Specific Position Of filename String, Log if True.
- :Filter_dll
- Set "testletter=!name[%val%]!"
- Set testletter=%testletter:~1,1%
- IF /I "!testletter!"=="i" (
- Set /a Found+=1
- ECHO [1;1H[K[36m Logging File... [31m[4m!location[%Val%]![0m [37m!Val! [33mFiles Searched[32m
- ECHO [3;1H[K[33m Found [37m!Found! [33mFiles[32m
- ECHO [2;1H[K[32m Last File Logged: [36m!name[%val%]!!EXT[%val%]!
- ECHO !location[%val%]!!name[%val%]!!EXT[%val%]!>>%Prog_Dir%files.txt
- ) else (
- ECHO [1;1H[K[33m Searching... [31m[4m!location[%Val%]![0m [37m!Val! [33mFiles Searched[32m
- )
- GOTO :EOF
- REM ::: Test Filename for Specific length with use of 'strlen' sub-function, Log if True.
- :Filter_com
- Call :strlen result !name[%val%]!
- IF !result!==4 (
- Set /a Found+=1
- ECHO [1;1H[K[36m Logging File... [31m[4m!location[%Val%]![0m [37m!Val! [33mFiles Searched[32m
- ECHO [3;1H[K[33m Found [37m!Found! [33mFiles[32m
- ECHO [2;1H[K[32m Last File Logged: [36m!name[%val%]!!EXT[%val%]!
- ECHO !location[%val%]!!name[%val%]!!EXT[%val%]!>>%Prog_Dir%files.txt
- ) else (
- ECHO [1;1H[K[33m Searching... [31m[4m!location[%Val%]![0m [37m!Val! [33mFiles Searched[32m
- )
- GOTO :EOF
- REM ::: Sub function using For loop to test a String against itself and Determine length of string.
- REM ********* function thanks to Jeb https://stackoverflow.com/users/463115/jeb *****************************
- :strlen <resultVar> <stringVar>
- set tmp=%~2
- If defined tmp (
- set "len=1"
- for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
- if "!tmp:~%%P,1!" NEQ "" (
- set /a "len+=%%P"
- set "tmp=!tmp:~%%P!"
- )
- )
- ) ELSE (
- set len=0
- )
- (
- set "%~1=%len%"
- exit /b
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement