Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

bat file split a string and loop results

Posted on 2011-03-10
8
Medium Priority
?
757 Views
Last Modified: 2012-05-11
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
Comment
Question by:awilderbeast
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 35093970
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
 
LVL 1

Author Comment

by:awilderbeast
ID: 35094081
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
 
LVL 85

Expert Comment

by:oBdA
ID: 35094181
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 1

Author Comment

by:awilderbeast
ID: 35094201
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
 
LVL 85

Expert Comment

by:oBdA
ID: 35094760
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
 
LVL 1

Author Comment

by:awilderbeast
ID: 35094845
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
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 35094958
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
 
LVL 1

Author Closing Comment

by:awilderbeast
ID: 35094972
Thanks alot!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question