I have a CSV file with a list of IP addresses and URL's for specified folders within that ftp.
I am using a tool to do work with the files converting them from one type to another and reloading back to the source.
The batch in it's entirety works fine, but I am needing to get the CSV imported and then the script to loop through its processes for each line in the CSV. As of now, it only uses the last line of the information.
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "tokens=1-2 delims=," %%a in (Convert.csv) do (
set IPAddress=%%a
set ProjectURL=%%b
)
ECHO Retrieving File
start /wait tool.exe get "ssh %IPAddress%" "%~dp0%IPAddress%\Backup" "%~dp0%IPAddress%\Report\Backup" --ctrl_path="%ProjectURL%"
ECHO Retrieved
Timeout 2 > NUL
ECHO Please wait as we... Convert file after retrieval
ECHO Converting File
start /wait tool.exe convert "%~dp0%IPAddress%\Backup" "%~dp0%IPAddress%\Converted" "%~dp0%IPAddress%\Report\Conversion" "%~dp0HTML.xml" --cnx="%~dp0CNX.xml"
ECHO Converted
Timeout 2 > NUL
ECHO Please wait as we... Push the file
ECHO Pushing File
start /wait tool.exe put "ssh %IPAddress%" "%~dp0%IPAddress%\Converted" "%~dp0%IPAddress%\Report\Placement" --ctrl_path="%ProjectURL%"
ECHO Completed
I understand that this pulls and it shows the variables updating, but I need the rest of the script to run for each line that is read and processed in this manner.
I have tried encompassing the entire script within the For /F loop and it does not seem to wait for the commands within to complete. It blasts through for each line of the CSV and thus does nothing at all.
Is there a looping mechanism to do this within batch?
I did get it to work by putting the entire code section within the loop and changing the variables inline to !IPAddress! and !ProjectURL! respectively, but it seems janky? Is there a cleaner method? This is what I currently have, it works but isn't at all pretty.
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "tokens=1-2 delims=," %%a in (Convert.csv) do (
set IPAddress=%%a
set ProjectURL=%%b
ECHO Retrieving File
start /wait tool.exe get "ssh !IPAddress!" "%~dp0!IPAddress!\Backup" "%~dp0!IPAddress!\Report\Backup" --ctrl_path="!ProjectURL!"
ECHO Retrieved
Timeout 2 > NUL
ECHO Please wait as we... Convert file after retrieval
ECHO Converting File
start /wait tool.exe convert "%~dp0!IPAddress!\Backup" "%~dp0!IPAddress!\Converted" "%~dp0!IPAddress!\Report\Conversion" "%~dp0HTML.xml" --cnx="%~dp0CNX.xml"
ECHO Converted
Timeout 2 > NUL
ECHO Please wait as we... Push the file
ECHO Pushing File
start /wait tool.exe put "ssh !IPAddress!" "%~dp0!IPAddress!\Converted" "%~dp0!IPAddress!\Report\Placement" --ctrl_path="!ProjectURL!"
ECHO Completed
)
start /WAITto run an executable? why not just runningtool.exe? istool.exea console application?