Solved

bat file split a string and loop results

Posted on 2011-03-10
8
740 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 500 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

689 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