Page 1 of 1

Making a batch file run faster

Posted: 19 Jan 2019 22:31
by plasma33
Hi guys,

I have a batch file that basically does the following each time:
-> Types the content of file1 into a text file (say fileA)
-> Then using the content of file1 performs a scan of a folder containing 900 files using an application called clamscan
-> Finally it saves the result into the same text file (i.e. fileA)
I have around 400k plus files to process and the steps above remain the same for every file. Right now it aprrox. takes 1.2 to 1.8 seconds to process each file. It is actually searching for a string one by one in the 900 files using clamscan and saves the results into a text file. I execute the batch file inside the folder containing that 900 files.

Part of my code is as follows:

Code: Select all

@echo off
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100001.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100001.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100002.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100002.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100003.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100003.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100004.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100004.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100005.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100005.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100006.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100006.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100007.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100007.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100008.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100008.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100009.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100009.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100010.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100010.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100011.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100011.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig100012.ndb" >> "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt" & "C:\Users\nv\Desktop\Clam\clamscan.exe" -d "C:\Users\nv\Desktop\Individual_sigs19\Sig100012.ndb" -l "C:\Users\nv\Desktop\Sig_Log_test_18_2.txt"
Thanks in advance
plasma33

Re: Making a batch file run faster

Posted: 22 Jan 2019 05:04
by jfl
If all your files are numbered sequentially, like they seem to be, then you simply need to use a (for /l) loop.
For example something like:

Code: Select all

setlocal EnableExtensions EnableDelayedExpansion
for /l %%n in (1,1,400000) do (
  set "N=00000%%n" &:# Make sure there are at least 6 digits
  set "N=!N:~-6!"  &:# Keep only the last 6 digits
  echo TYPE "C:\Users\nv\Desktop\Individual_sigs19\Sig!N!.ndb" ...
)
Run (for /?) to get help about loops.