Computing.Net > Forums > Programming > Advanced Batch Files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Advanced Batch Files

Reply to Message Icon

Name: MikeKozar
Date: June 1, 2009 at 17:50:25 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

I'm trying to get a batch file to remove
%SUBSET% from %VARIABLE%, and let me
use the remainder as %RESULT%. However,
I can't seem to get the SET command to parse
a nested string;

SET RESULT=%VARIABLE:%SUBSET%=%

...for instance, sets %RESULT% equal to
SUBSET...not the value of the variable
%SUBSET%, but the string SUBSET.

Replacing the % symbols with ! symbols gives
the same result.

I've been able to work around this by using
ECHO to build a second, temporary batch file
where %SUBSET% is rendered as a literal
string, and reading the output of that batch file
into a temporary text file and back into the
calling batch file, but that's pretty roundabout.

Anybody know how to do a simple string
replace with two variables? I'm on XP.




Response Number 1
Name: reno
Date: June 1, 2009 at 22:08:18 Pacific
+1
Reply:

add a call in front of the statement

call SET RESULT=%%VARIABLE:%SUBSET%=%%



Response Number 2
Name: IVO
Date: June 2, 2009 at 02:21:34 Pacific
+1
Reply:

setlocal EnableDelayedExpansion
set RESULT=!VARIABLE:%SUBSET%=!

When using variable of variable the ! must mark the outer one.


Response Number 3
Name: MikeKozar
Date: June 2, 2009 at 12:24:37 Pacific
+1
Reply:

Thanks, guys!

I tested both solutions, and they both do exactly what I
needed. You guys just made my script %20 faster - great
work.

~Mike



Reply to Message Icon

Related Posts

See More


Batch File Save Game Hi, need one help!!



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Google Ads



Results for: Advanced Batch Files

advanced batch file help needed www.computing.net/answers/programming/advanced-batch-file-help-needed/8803.html

Advanced bat file for copying files www.computing.net/answers/programming/advanced-bat-file-for-copying-files/17021.html

Batch File Formmatting Help, Please www.computing.net/answers/programming/batch-file-formmatting-help-please/14040.html