Making a batch file run faster

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
plasma33
Posts: 22
Joined: 26 Jul 2017 21:18

Making a batch file run faster

#1 Post by plasma33 » 19 Jan 2019 22:31

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

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Making a batch file run faster

#2 Post by jfl » 22 Jan 2019 05:04

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.

Post Reply