Solved

bat file split a string and loop results

Posted on 2011-03-10
8
694 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 82

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 82

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 82

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 82

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

12 Experts available now in Live!

Get 1:1 Help Now