-2

I need to create a batch that list all files in folder and subfolders that contain the var %search% in the name and then list then with numbers per line so i can write the line number and it opens the specified file.

I have this but i cant change the output

dir *%search%*.* /s

Any thought are welcome thanks

Done, down the full working script

@ECHO OFF

cd..
set cdstart=%cd%

echo.
echo :::::::::::::::::::::::::::::Ultimo Ficheiro Gerado por Tipo::::::::::::::::::::::::::::::::::::::
ECho.
cd %cdstart%\old\old_states\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo state: %LAST%
ECHO.
cd %cdstart%\old\old_Doc\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo Documentos: %LAST%
ECHO.
cd %cdstart%\old\old_Processo\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo Processo: %LAST%
ECHO.
cd %cdstart%\old\OLD_COMPRESS\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo ficheiro Comprimido: %LAST%
ECHO.
cd %cdstart%\old\old_Utilizadores\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo Utilizador Criado/Alterado: %LAST%
ECHO.


ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
cd %cdstart%

ECHO.
set /p search=Introduza o Id a pesquisar:
ECHO.
set old_mypath=%cd%

dir /s /b **%search%*.**|findstr /n "^"
dir /s /b **%search%*.**|findstr /n "^" >>output_search.txt

echo.
echo.

set /p linha=Qual o ficheiro que deseja abrir?
set /a linhaf = %linha%-1
echo %linhaf%
set "xprvar="
for /F "skip=%linhaf% delims=" %%i in (output_search.txt) do if not defined xprvar set "xprvar=%%i"

if %linha% GEQ 100 goto :maiorcem
if %linha% GEQ 10 goto :maiornove
if %linha% LEQ 9 goto :menornove

:menornove
echo menornove
set stre=%xprvar:~2%
echo %stre%
START notepad++.exe "%stre%"
goto escolha_2

:maiornove
echo maiornove
set stre=%xprvar:~3%
echo %stre%
START notepad++.exe "%stre%"
goto escolha_2

:maiorcem
echo maiorcem
set stre=%xprvar:~4%
echo %stre%
START notepad++.exe "%stre%"
goto escolha_2

:escolha_2
del output_search.txt
exit
razstec
  • 21
  • 4
  • 1
    `dir /s /b *test*|findstr /n "^"`. Answers your question, but I'm afraid, that won't help you. – Stephan May 30 '17 at 16:25
  • 1
    [possible duplicate](https://stackoverflow.com/q/30592253/2152082). Accepted answer should be easy to adapt to your needs. – Stephan May 30 '17 at 16:38
  • It worked great, now to read the file, can i write the return to a txt? i could tell him to get the specific line and put it in a var and then just start var – razstec May 30 '17 at 16:57
  • Got it :: dir -o test.txt /s /b **%search%*.**|findstr /n "^" :: now i just need to place a set where the user puts the number and a start from the line number of the txt that is generated, any ideas to get the line number from another txt as a variable? – razstec May 30 '17 at 17:04
  • 2
    Possible duplicate of [.bat - Create a menu from folder file list](https://stackoverflow.com/questions/30592253/bat-create-a-menu-from-folder-file-list) –  May 30 '17 at 22:00
  • Not the same but close. – razstec May 31 '17 at 07:42

1 Answers1

0

@ECHO OFF

cd..
set cdstart=%cd%

echo.
echo :::::::::::::::::::::::::::::Ultimo Ficheiro Gerado por Tipo::::::::::::::::::::::::::::::::::::::
ECho.
cd %cdstart%\old\old_states\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo state: %LAST%
ECHO.
cd %cdstart%\old\old_Doc\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo Documentos: %LAST%
ECHO.
cd %cdstart%\old\old_Processo\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo Processo: %LAST%
ECHO.
cd %cdstart%\old\OLD_COMPRESS\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo ficheiro Comprimido: %LAST%
ECHO.
cd %cdstart%\old\old_Utilizadores\
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i 
echo Ultimo Utilizador Criado/Alterado: %LAST%
ECHO.


ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
cd %cdstart%

ECHO.
set /p search=Introduza o Id a pesquisar:
ECHO.
set old_mypath=%cd%

dir /s /b **%search%*.**|findstr /n "^"
dir /s /b **%search%*.**|findstr /n "^" >>output_search.txt

echo.
echo.

set /p linha=Qual o ficheiro que deseja abrir?
set /a linhaf = %linha%-1
echo %linhaf%
set "xprvar="
for /F "skip=%linhaf% delims=" %%i in (output_search.txt) do if not defined xprvar set "xprvar=%%i"

if %linha% GEQ 100 goto :maiorcem
if %linha% GEQ 10 goto :maiornove
if %linha% LEQ 9 goto :menornove

:menornove
echo menornove
set stre=%xprvar:~2%
echo %stre%
START notepad++.exe "%stre%"
goto escolha_2

:maiornove
echo maiornove
set stre=%xprvar:~3%
echo %stre%
START notepad++.exe "%stre%"
goto escolha_2

:maiorcem
echo maiorcem
set stre=%xprvar:~4%
echo %stre%
START notepad++.exe "%stre%"
goto escolha_2

:escolha_2
del output_search.txt
exit
razstec
  • 21
  • 4