Windows Page: verschil tussen versies
Uit Mike´s Wiki
(Nieuwe pagina aangemaakt met '= Lines cmd = {| border="0" cellspacing="0" cellpadding="1" style="border-width: 1px; border-spacing: 2px; font-size:11px;" |+ ''' Shows content of file with line...') |
k |
||
| Regel 8: | Regel 8: | ||
pause | pause | ||
goto :eof | goto :eof | ||
| + | |||
| + | = Search cmd = | ||
:enumerate FileName | :enumerate FileName | ||
| Regel 20: | Regel 22: | ||
</pre> | </pre> | ||
|} | |} | ||
| + | |||
| + | {| border="0" cellspacing="0" cellpadding="1" style="border-width: 1px; border-spacing: 2px; font-size:11px;" | ||
| + | |+ ''' find a file in the search path.''' | ||
| + | |<pre> | ||
| + | @echo off | ||
| + | |||
| + | set pvar=%path% | ||
| + | set searchfilename=java.exe | ||
| + | |||
| + | :startloop | ||
| + | |||
| + | for /f "tokens=1* delims=;" %%a in ("%pvar%") do ( | ||
| + | echo Searching for %searchfilename% in: %%a | ||
| + | dir /b "%%a" 2>nul|findstr /i /r "\<%searchfilename%\>">nul && echo.%searchfilename% Found in: %%a | ||
| + | set pvar=%%b | ||
| + | ) | ||
| + | |||
| + | if "%pvar%"=="" goto endloop | ||
| + | goto startloop | ||
| + | |||
| + | :endloop | ||
| + | </pre> | ||
| + | |} | ||
| + | |||
| + | [[Category:script]] | ||
Versie van 31 dec 2015 om 15:12
Lines cmd
@echo off &setlocal
call :enumerate %1
pause
goto :eof
= Search cmd =
:enumerate FileName
for /f "tokens=* delims=1234567890" %%a in ('type "%~1"^|findstr /n "^"') do (
set "line=%%a"
set /a n+=1
setlocal enabledelayedexpansion
echo(!n!. !line:~1!
endlocal
)
goto :eof
|
@echo off
set pvar=%path%
set searchfilename=java.exe
:startloop
for /f "tokens=1* delims=;" %%a in ("%pvar%") do (
echo Searching for %searchfilename% in: %%a
dir /b "%%a" 2>nul|findstr /i /r "\<%searchfilename%\>">nul && echo.%searchfilename% Found in: %%a
set pvar=%%b
)
if "%pvar%"=="" goto endloop
goto startloop
:endloop
|