Avatar of ivan rosa
ivan rosa
Flag for United States of America asked on

batch script capturing strings

Hello Colleagues,

I created the following batch script that allows me to copy shortcuts to multiple PCs...
for /f %%a in (clients.txt) DO copy C:\folder1\*.url "\\%%a\\c$\Users\Public\Desktop\" /y

Open in new window


which gives generates me a message like so
 1 file(s) copied.

Open in new window


is there any way to capture this result and depending of the success or not, would actually give me a csv, eg. below.
Any help would be most appreciative (unfortunately I didn't learn how to play with tokens nor |findstr ) but i'm open for a lecture..

Capture.PNG
Windows BatchScripting LanguagesProgramming Languages-OtherProgramming

Avatar of undefined
Last Comment
ivan rosa

8/22/2022 - Mon
NVIT

Assuming the first line of FNResults.csv is:
Success,Failed

Open in new window


set FNResults=FNResults.csv
for /f %%a in (clients.txt) DO copy C:\folder1\*.url "\\%%a\\c$\Users\Public\Desktop\" /y
if errorlevel 1 (
  >> %FNResults% echo ,%%a
) else (
  >> %FNResults% echo %%a,
)

Open in new window


Personally, I'd go with a format like this. FNResults.csv:
Date,Client,Result

Open in new window


set FNResults=FNResults.csv
for /f %%a in (clients.txt) DO copy C:\folder1\*.url "\\%%a\\c$\Users\Public\Desktop\" /y
if errorlevel 1 (
  >> %FNResults% echo %date% %time%,%%a,Failed
) else (
  >> %FNResults% echo %date% %time%,%%a,Success
)

Open in new window

ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ivan rosa

ASKER
Thanks NVIT, for your interest on help, although I have to agree with oBdA, unfortunately the script did not work. let's just call it beta1  

As usual oBdA you nailed it, Thanks for looking out

I appreciate you guys effort and knowledge, hopefully one day I get half good
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes