• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 769
  • Last Modified:

bat file split a string and loop results

HI all i have my code below

but what i wanted to do, is for file name to be able to insert multiple file names seperated by commas then loop the results

so filename = file1, file2, file3, file4, file5, file6

results = filename.split(",");
for each(file in results){
%ProgramPath% %ResourceFolder%\Icons16\%file%.png" %ResourceFolder%\Icons16\%file%.bmp"
}

i think you get what i mean by the above anyway

someone help me out modifying this?

Thanks
@echo off
cls
set ProgramPath="\\domain.local\convert2bmp.exe"
set ResourceFolder="\\domain.local\Resources

echo Pick a source folder
echo 1. Icons 16 Folder
echo 2. Icons 32 Folder
set /p choice=
echo Enter FileName without extentsion(only accepts png's)
set /p FileName=
if '%choice%'=='1' goto :1
if '%choice%'=='2' goto :2

:1
%ProgramPath% %ResourceFolder%\Icons16\%FileName%.png" %ResourceFolder%\Icons16\%FileName%.bmp" 
goto :EOF

:2
%ProgramPath% %ResourceFolder%\Icons32\%FileName%.png" %ResourceFolder%\Icons32\%FileName%.bmp" 
goto :EOF

Open in new window

0
awilderbeast
Asked:
awilderbeast
  • 4
  • 4
1 Solution
 
oBdACommented:
Try something like this (comma is not necessary, and a file name with a space needs to be enclosed in quotes).
Note that the "ProgramPath" variable in your script is not valid; there's no share

@echo off
cls
set ProgramPath="\\domain.local\convert2bmp.exe"
set ResourceFolder=\\domain.local\Resources

echo Pick a source folder
echo 1. Icons 16 Folder
echo 2. Icons 32 Folder
set /p choice=
echo Enter space separated file name list without extension ^(only accepts pngs^)
set /p FileNameList=
if '%choice%'=='1' (set Source=Icons16)
if '%choice%'=='2' (set Source=Icons32)

for %%a in (%FileNameList%) (
  %ProgramPath% "%ResourceFolder%\%Source%\%%~a.png" "%ResourceFolder%\%Source%\%%~a.bmp"
)
0
 
awilderbeastAuthor Commented:
that comes back with

Pick a source folder
1. Icons 16 Folder
2. Icons 32 Folder
2
Enter space separated file name list without extension (only accepts pngs)
newspaper_add newspaper_delete
( was unexpected at this time.
C:\Windows\system32>
0
 
oBdACommented:
Sorry, simply a "do" missing:
@echo off
cls
set ProgramPath="\\domain.local\convert2bmp.exe"
set ResourceFolder=\\domain.local\Resources

echo Pick a source folder
echo 1. Icons 16 Folder
echo 2. Icons 32 Folder
set /p choice=
echo Enter space separated file name list without extension ^(only accepts pngs^)
set /p FileNameList=
if '%choice%'=='1' (set Source=Icons16)
if '%choice%'=='2' (set Source=Icons32)

for %%a in (%FileNameList%) do (
  %ProgramPath% "%ResourceFolder%\%Source%\%%~a.png" "%ResourceFolder%\%Source%\%%~a.bmp" 
)

Open in new window

0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
awilderbeastAuthor Commented:
now i get
Pick a source folder
1. Icons 16 Folder
2. Icons 32 Folder
1
Enter space separated file name list without extension (only accepts pngs)
newspaper_add newspaper_delete
Error: Invalid parameters number.
Error: Invalid parameters number.

C:\Windows\system32>
0
 
oBdACommented:
That's a syntax error with "convert2bmp.exe" then.
Put an ECHO in front of the "%ProgramPath% ..." line to see the commands that are created, and check which syntax requirements "convert2bmp.exe" has.
0
 
awilderbeastAuthor Commented:
got it! found the error its working now :)

is tehre anyway i can make it pause on error?

or perhaps stop at the end, press q to quit or n to start the script again?

thanks
0
 
oBdACommented:
Just put a loop around the main part:
@echo off
cls
set ProgramPath="\\domain.local\convert2bmp.exe"
set ResourceFolder=\\domain.local\Resources
:Loop
echo Pick a source folder
echo 1. Icons 16 Folder
echo 2. Icons 32 Folder
set /p choice=
echo Enter space separated file name list without extension ^(only accepts pngs^)
set /p FileNameList=
if '%choice%'=='1' (set Source=Icons16)
if '%choice%'=='2' (set Source=Icons32)

for %%a in (%FileNameList%) do (
  %ProgramPath% "%ResourceFolder%\%Source%\%%~a.png" "%ResourceFolder%\%Source%\%%~a.bmp" 
)
set /p Continue=Press Q to quit, any other key to run again:
if /i "%Continue%"=="Q" goto Loop

Open in new window

0
 
awilderbeastAuthor Commented:
Thanks alot!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now