tags:

views:

76

answers:

1

how do i get rid of mid spaces in an environment variable suppose i have the following for loop fragment that get free disk space size of a certain disk

for /f "tokens=3" %%i in ('dir ^| find "Dir(s)"') do set size=%%i

would result something like this

C:\>set size=129,028,096

i wanted to get rid of delims as follows

for /f "delims=," %%i in ('echo %size%') do set size=%%i

and resulted something like this

set size=129 028 096

how can i get it with no mid spaces or delims with native tools thanks in advance

+1  A: 

You can use

set size=%size: =%

afterwards which will replace all spaces with nothing.

But you can also do that with commas :)

But keep in mind that (a) the delimiter changes, it's a dot for me, not a comma. That may depend on your OS language or regional settings. And (b) you can't really do math with that value afterwards as cmd is limited to signed 32-bit math (using set /a).

Your second for statement won't work properly, by the way, since it will just set size to the last digit group. That can be circumvented but I'd rather advise to use the replacing directly on commas/dots:

set size=%size:,=%
set size=%size:.=%
Joey
Thanks alot thats outstanding can i do it in one step
thank you very much
Less than two lines probably not. But that should be short enough. You can try to use tokenizing and then just concatenate each token, but depending on your HDD size that may result in one token more or less ... certainly not ideal. I'd go with your first line and then replace all commas.
Joey