Create bat to move files returned by findstr

1

Good afternoon everyone!

I have encountered a problem every day where, I have several .xml to open and check if they have tags:

< desc_produto >Riscos< /desc_Produto >"

or

< tp_mov>P01< /tp_mov>

To do this, I was performing this procedure manually, but I decided to make a .bat that can make my life easier. I found the findstr command that performs this procedure (Windows 7). So far I'm just running the following command at the prompt:

findstr /i /s "< desc_produto>Riscos< /desc_Produto>" *. *

However, I'd like to improve .bat where, when I run it, the system checks the contents of all the .xml files to find the files that have this text tag. And when you find these files, you create a Risks folder and move them into it.

Could someone please help me with this need?

    
asked by anonymous 24.04.2017 / 17:09

1 answer

1

Use for to scroll through your search result with findstr .

Create a batch findtags.bat with the following content:

@echo off
rem Garante que as variáveis de ambiente tenham escopo local
    setlocal
rem Cria diretório não retornando erro se já existe
    if not exist Riscos\. md Riscos
rem Busca em subdiretórios retornando nome dos arquivos encontrados
    for /f %%a in ('findstr /I /S /M "< desc_produto>Riscos< /desc_Produto>" *.*') do (
        echo Movendo %%a
        move %%a Riscos\
    )
    endlocal
    
24.04.2017 / 18:47