#1 28 Apr 2019 02:48

caspertone2003
Member
Registered: 28 Apr 2019
Posts: 2

string substitution in for loops and also in subroutines

When in a batch using FOR /F %%K (whatever) do (command)

I wish to do in the command string manipulation with %%K , so I use
set _temp=%%K
and then set _new=!_temp:0,-2% (as example)

Is there any way to use %%K instead of that intermediate variable?
I tried some combinations with %%K to no luck...

How to proceed for same with subroutines, where we have %1, %2 etc.

TIA

Offline

#2 28 Apr 2019 22:15

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,092

Re: string substitution in for loops and also in subroutines

There are a few ways you can work with substrings of %%K but these are based around file name manipulation, rather than slicing at offsets.

For example:

%%~K removes surrounding quotes
%%~fxK gets the file name and extension, such as the "Some file.ext" part of "C:\Some Dir\Some file.ext"
%%~dpK gets the disk and path part, such as "C:\Some Dir\"

Unless one of the available modifications work for your use case, you're stuck using an intermediate variable.


cmd | *sh | Ruby | Chef

Offline

Board footer

Powered by FluxBB