Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @REM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: Batch program to Search for files. :::
- ::: Results stored in a .log file using a 3rd parameter :::
- ::: A fourth parameter VarName returns the number of files to that Variable. :::
- ::: - When called from a batch file, the results may be retrieved from an array using: :::
- ::: For /L %%i in (1,1,!Param4!) Do Echo !File.Loc[%%i]! :::
- @Echo off & CD "%~dp0" & Title Filefinder by T3RRY & REM :::
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: { Creates variable Æ = Ascii-27 Escape code, Used to Display output in multiple Colors.
- ::: - http://www.dostips.com/forum/viewtopic.php?t=1733
- ::: - https://stackoverflow.com/a/34923514/12343998
- :::
- ::: - Æ (Alt 146) can be used with and without DelayedExpansion.
- Setlocal
- For /F "tokens=2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
- Endlocal
- Set "Æ=%%a"
- )
- ::: }
- Echo.%Æ%[31m & REM
- IF Not "%~1" == "" IF Not Exist "%~1" (
- Echo.Folder %Æ%[33m"%~1" %Æ%[31mDoes Not Exist%Æ%[0m
- Echo.
- Echo.%Æ%[31mWhereis Usage:
- Echo.%Æ%[33m^<Root Directory^> ^<*.*^> ^<Optional - Output File^> ^<Optional - IndexVar^>%Æ%[0m
- Pause > Nul
- Exit /B 1
- )
- IF "%~2" == "" (
- Echo.Whereis Usage:
- Echo.%Æ%[33m^<Root Directory^> ^<*.*^> ^<Optional - Output File^> ^<Optional - IndexVar^>%Æ%[0m
- Pause > Nul
- Exit /B 1
- )
- :FileFinder
- ::: - Search Recursively through the declared directory for all copies of files matching the search term
- ::: - Assigns the results to an array
- ::: - Parameters 1 and 2 should be quoted. Results will be more accurate if an extension is Provided for Param 2.
- SetLocal EnableDelayedExpansion
- Set "R#="
- For /F "UsebackQ Tokens=* delims=" %%W in (`WHERE /R "%~1" /F "%~2"`) Do (
- Set /A "R#+=1"
- Set "File.Loc[!R#!]=%%~W"
- )
- IF Not "%~3" == "" (
- Echo %Date% %Time: =0%
- )>>"%~3.log"
- For /L %%i in (1,1,!R#!) Do (
- For %%A in ("!File.Loc[%%i]!") Do (
- Echo %Æ%[33m%%~nxA %Æ%[90mis located in:
- Echo %Æ%[36m%%~dpA%Æ%[0m
- IF Not "%~3" == "" (>>"%~3.log" Echo %%~dpnxA)
- )
- )
- If Not "%~4" == "" (Set "%~4=!R#!")
- Echo.%Æ%[0m & Rem
- Exit /B 0
Add Comment
Please, Sign In to add comment