Solved

bat file split a string and loop results

Posted on 2011-03-10
8
703 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
  • 4
  • 4
8 Comments
 
LVL 83

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 83

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 83

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 83

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now