Cmd - query and export in single file. Sql

Asked

Viewed 120 times

1

I have a folder with several sub-folders containing several arquivos.SQL

I wonder if you have any command of cmd to search and copy to a single file all my files .SQL found.

I was able to do this only by exporting the filenames, but not their content.

Commando:

C:\Users\jefer\Desktop\Integracao>dir /s .sql > todos_scripts.sql

This command lists all the titles of the found files. I would like to copy and export the contents of the files below each other.

I would like to look for a solution of the type below, but using a dir or find and merging results for a single result.

Commando:

C:\Users\jefer\Desktop\Integracao>copy *.sql todos_scripts.sql

Another thing I thought was to unify two commands, but I suppose it’s not possible.

Wrong example:

dir /s .sql | copy *sql listao.sql
  • make a foreach in the contents of the generated file, for example: for %%f IN (todos_scripts.sql) do coloque-seu-comando-copy-aqui, or because it does not make a foreach and already runs the command instead of generating a file with the scripts?

1 answer

0

Try using for /r loop with copy /b /y listao.sql+"file_in_loop" listao.sql :

>nul cd.2>listao.sql & for /r "C:\Users\jefer\Desktop\Integracao" %i in (*.sql)do copy /y /b .\listao.sql+"%~i" listao.sql

These commands concatenate all your files .sql recursively in a single (list.sql) folder in the current folder.

To specify the location to save the file listao.sql

>nul cd.2>"c:\pasta\salva\listao.sql" & for /r "C:\Users\jefer\Desktop\Integracao" %i in (*.sql)do copy /y /b "c:\pasta\salva\listao.sql"+"%~i" "c:\pasta\salva\listao.sql"

Obs.: Save your file listao.sql in a different folder/sub-folder from where the loop will go, thus avoiding duplication of cumulative copies during processing.

  • Thanks for all your help.

  • @Jéfersonmöller Trankilo Tchê, good that it worked

  • Thank you very good. I learned something new.

  • Sorry my ignorance. How do I put as solved and download this question?

  • This command you sent was very good. I ask you. Do I have the possibility to adapt it to type modification date range per file or folder? Type start date and it copies the start date range to today.

  • @There’s a way to do that, yes, but I suggest you ask another question.

  • @Jéfersonmöller Good morning. Managed to make some adaptation by date, in the selection of files?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.