Boost Performance Bat

Asked

Viewed 294 times

1

Currently I have a . bat that runs copying files from the network from one server to another. This made a job that was done manually much easier, but I noticed that by removing some increments (flourishes) from . bat, he improved his performance of running the copies of the files.

I’ll be posting the code. bat and if possible, could help me perform it, making it shorter, performative, but maintaining its main goal.

The goal is to take ids from a.txt list and copy the files with their Ids to another network folder. NOTE: I was pouring in a log in case I didn’t find the file but I’m not needed so I removed it.

@echo off

rem Pasta para colar os arquivos copiados.  
set minhaPasta=I:\ARQUIVOS_ENCONTRADOS

rem Arquivo txt que o processo vai ler com o nome dos arquivos "LISTA DOS IDs".  
set meuArquivo=I:PASTA\lista.txt  

rem Pasta onde estão os arquivos que devem ser copiados, tem que ter a barra no final "\".  
set pastaArquivos=J:\  

rem Extensão dos arquivos a serem copiados.  
set tipo=.xml  

rem Comando para criar as pastas caso elas não existam no meu computador  
rem if not exist %minhaPasta% md %minhaPasta%  

rem Caso o arquivo que tem os nomes dos arquivos não exista vai gravar o log informando.  

rem Inicio da verificação  
for /F "tokens=*" %%A in (%meuArquivo%) do (      
        copy %pastaArquivos%*%%A*%tipo% %minhaPasta%   
    )
pause

Is it possible to improve the performance of this . bat? Would you have any tips? Not including or decreasing variables, remove comments, run location and not use variables, etc...

2 answers

2

I don’t think it will improve the performance in BATCH itself, it seems simple enough, but avoid using special characters even in the comments, such as letters with accents and cedilla, also avoid leaving too many spaces before the line breaks, may be nothing, but it is also something to be written on the command prompt screen.

In the FOR has twice the "*", unless it is necessary for the default name used in the files.

I did the test simulating the code, but instead of copying to another machine, I copied to a PEN-DRIVE.

To see the script run more clearly I put these commands at the beginning:

@echo off
cls

You can scan or stop the Script if any file is not found with errorlevel within the FOR:

IF %ERRORLEVEL% NEQ 0 echo ERRO AO TRANSFERIR ARQUIVO DE ID %%A

What you can improve is communication between machines, putting network cable avoiding the use of connection wireless, also fixing the IP’s with the same class to prevent network crash.

0

1) Use qualified paths instead of variables

2) Directly create the folder by hiding the error in case it already exists 2>nul mkdir "I:\ARQUIVOS_ENCONTRADOS"

3) Grouping () and redirected >> to the output file >>"%temp%\Log_Rotina_.log" (..)

4) Use paths instead of variables in the command copy and also redirecting >nul

  • copy "J:\%%~A*.xml" "I:\ARQUIVOS_ENCONTRADOS\" >nul
@echo off & 2>nul mkdir "J:\SUA_PASTA_DESTINO\"
>> "%temp%\Log_Rotina_MeuArquivo_MinhaPasta_.log" (
for /F tokens^=* %%A in ("I:\PASTA\lista.txt"
)do copy "J:\%%~A*.xml" "I:\ARQUIVOS_ENCONTRADOS\" >nul )

  • or...
@echo off &(2>nul mkdir "J:\SUA_PASTA_DESTINO\")& >> "%temp%\Log_Rotina_MeuArquivo_MinhaPasta_.log" (for /F tokens^=* %%A in "I:\PASTA\lista.txt")do copy "J:\%%~A*.xml" "I:\ARQUIVOS_ENCONTRADOS\" >nul )`

Browser other questions tagged

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