Hello,
I have a manual process which I update the MS SQL database with 4 files. I would like to automate this process by executing a script that will check the directory for 4 files and execute another script that will update the database.
Name and location of the files are (All files have basefile name "VEND":
d:\vendor\VEND_NAME
d:\vendor\VEND_ADDRESS
d:\vendor\VEND_PHONE
d:\vendor\VEND_NUMBER
Name and location of script to be trigger:
d:\script\dts.cmd
Script steps:
1. Find all files in d:vendor with base filename VEND
This is the command I found and tested: dir /b "d:\vendor\VEND*" | find /c /v ""
2. If there all 4 Vendor files (VEND*) found in step 1, execute the script dts.cmd
3. If there not all 4 Vendor files (VEND*) found in step 1, exit without executing the dts.cmd
Thank you in advance for your help
***Below is what I have so far, but need help to get the script to work***
===============================================
@ECHO OFF
:: Find if there are 4 Vendor files (VEND*) exist
dir /b "d:\vendor\VEND*" | find /c /v ""
:: If 4 Vendor files (VEND*) exist, run DTS script
if <<need help with syntax>>
goto RUNDTS
:: If 4 Vendor files (VEND*) NO exist, bail and exit script
ELSE
goto:EOF
:RUNDTS
d:\script\dts.cmd
trigger another script after it receive x number of files
Moderator: DosItHelp
Re: trigger another script after it receive x number of file
I assume you need only one line
The trick is to get the output of FIND into a variable. This can be done via FOR /F.
Regards
aGerman
Code: Select all
for /f %%i in ('dir /a-d /b "d:\vendor\VEND*"^|find /c /v ""') do if %%i==4 call "d:\script\dts.cmd"
The trick is to get the output of FIND into a variable. This can be done via FOR /F.
Regards
aGerman
Re: trigger another script after it receive x number of file
aGerman,
Thank you. I tested the script and it works Great!
Thanks again.
Thank you. I tested the script and it works Great!
Thanks again.
Re: trigger another script after it receive x number of file
I always think that simpler methods are easier to understand and modify, and run faster also:
Code: Select all
@echo off
set i=0
for %%f in (d:\vendor\VEND*) do set /A i=i+1
if %i% == 4 call d:\script\dts.cmd
Re: trigger another script after it receive x number of file
Both aGerman's and Aacini's solutions should check to see if the count is >= 4. Otherwise a 5th VEND* file will cause the solution to fail.
What if VEND_COUNTRY exists, but VEND_ADDRESS does not? It's probably safer to look for each required file explicitly:
Dave Benham
What if VEND_COUNTRY exists, but VEND_ADDRESS does not? It's probably safer to look for each required file explicitly:
Code: Select all
for %%f in (
VEND_NAME
VEND_ADDRESS
VEND_PHONE
VEND_NUMBER
) do if not exist d:\vendor\%%f exit /b
d:\script\dts.cmd
Dave Benham