Get-keys.bat

@echo off REM get-keys.bat REM Recursively search for likely keys/tokens in files and generate a CSV report. REM Usage: REM get-keys.bat [root_path] [--extensions=ext1,ext2,...] [--exclude=pattern1;pattern2] [--mask] [--dry-run] REM Defaults: REM root_path = current directory REM extensions = txt,env,conf,config,json,js,py,java,xml,ini,yml,yaml,md,log REM exclude = .git;.venv;node_modules;venv REM mask = redact found values in report REM dry-run = do not write report (only console output)

REM findstr in Windows supports limited regex; some syntax above may not be portable. REM We'll use simpler multiple findstr searches per pattern below.

call :mask_value "%MATCHVAL%" set "OUTVAL=%MASKED_VALUE%" REM Quote fields for CSV, replace quotes inside fields set "QFILE=%%~fF" set "QLINE=%LN%" set "QCTX=%L%" REM escape double quotes by doubling them set "QFILE=%QFILE:"=""%" set "QCTX=%QCTX:"=""%" if "%DRY%"=="0" ( >>"%OUTFILE%" echo "%QFILE%","%QLINE%","%QCTX%","%MT%","%OUTVAL%" ) echo Found [%MT%] in %%~fF:%LN% -> %OUTVAL% ) ) ) ) get-keys.bat

setlocal ENABLEDELAYEDEXPANSION

:: Convert extensions list into a findstr include filter set "EXT_FILTER=" for %%E in (%EXTS:,= %) do ( if defined EXT_FILTER (set "EXT_FILTER=!EXT_FILTER! *.%%E") else set "EXT_FILTER=*.%%E" ) @echo off REM get-keys

:: Timestamp for report for /f "tokens=1-6 delims=/:. " %%a in ("%date% %time%") do ( set "DT=%%a-%%b-%%c_%%d-%%e-%%f" ) if "%DT%"=="" ( REM fallback set "DT=%DATE%_%TIME%" set "DT=%DT::=-%" set "DT=%DT:/=-%" set "DT=%DT: =_%" set "DT=%DT:.=-%" )

:: -------------------------- :: Defaults and arguments :: -------------------------- set "ROOT=%~1" if "%ROOT%"=="" set "ROOT=%CD%" "%OUTFILE%" echo "%QFILE%"

set "OUTFILE=%CD%\get-keys_report_%DT%.csv"