Windows batch: send multiple files based on a txt file

Luis Diaz
Luis Diaz used Ask the Experts™
on
Hello experts,
I have the following code which allows me to send single file to a website.
I would like to modify as following:
1-Add a for each loop and place the various names in another list.txt file. Script should loop the various names reported in the the list.txt and send files.
If you have questions, please contact me.
Thank you in advance for your help.

@echo off

rem Set curl path.
set CURL="curl/curl"

cd "%cd%"

rem Set site url.
set SITE_URL=

rem Set login.
set LOGIN=

rem Set password.
set PASSWORD=

rem Set service number.
Set SERVICE_NUMBER =

rem Set action url.
set ACTION_URL=%SITE_URL%/sendFile/%SERVICE_NUMBER%

rem Set input file path and name.
set PARAM_PROXY=

set FILE="file=@toto.csv"

rem Import the file.
curl -v -k %ACTION_URL% -u %LOGIN%:%PASSWORD% -F %FILE%

pause

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT / Software Engineering Consultant
Top Expert 2016
Commented:
Here's a starting place for you.  Basically anything that does not depend on the file name can stay outside the FOR loop, but I wasn't sure of all of those since you don't have values provided in your example, which I understand you did due to sensitive values in some cases.  Adjust as needed.

@echo off
setlocal EnableDelayedExpansion

set FileList=c:\temp\filelist.txt

rem Set curl path.
set CURL="curl/curl"

cd "%cd%"

rem Set site url.
set SITE_URL=

rem Set login.
set LOGIN=

rem Set password.
set PASSWORD=

rem Set service number.
Set SERVICE_NUMBER=

rem Set action url.
set ACTION_URL=%SITE_URL%/sendFile/%SERVICE_NUMBER%

rem Set input file path and name.
set PARAM_PROXY=

for /F "tokens=*" %%F in ('type "%FileList%") do (
    rem Import the file.
    curl -v -k %ACTION_URL% -u %LOGIN%:%PASSWORD% -F "file=@%%~F"
)

pause

Open in new window


»bp
Luis DiazIT consultant

Author

Commented:
Thank you Bill.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial