Denis
Denis

Reputation: 127

Batch variables remove line break

setlocal enabledelayedexpansion

... a lot of batch script ...
IF ... a lot of batch script ...    

for /f "skip=2 delims== tokens=2" %%g in ('WMIC DATAFILE WHERE ^"Name^='!filePath!'^" GET Version /value') DO (
    set fileVersion=%%g
)

ECHO Version: !fileVersion!

set nightlyBuildFullPath=%2\Setups\Nightly Builds\!fileVersion!\Full\

ECHO FullPath: !nightlyBuildFullPath!

Result:

Version: 1.5.1810.202

FullPath: C:\test\Setups\Nightly Builds\1.5.1810.202
\Full\

I want to remove the linebreaks in the fileVersion variable because I have to build a path for later use. If I actually build the path string I have a linebreak in it, which corrupts my path.

Upvotes: 1

Views: 2642

Answers (4)

GunterZile
GunterZile

Reputation: 1

REM :: As you use the commutator '/Value', you can use it to parse for command.

set myParams = WMIC DATAFILE WHERE ^"Name^='!filePath!'^" GET Version /value

for /f "tokens=1-2 skip=1 delims==" %%i in ('wmic /node:"%1" %myParams%') do if "%%i" == "Version" set "myVers=%%j"

REM :: DOS commands have the advantage of being able to run natively on all Microsoft systems. This can be useful when you have obsolete systems or when system or network security limits the execution of system commands.

Upvotes: -2

lit
lit

Reputation: 16236

Put the following line into a file named veronly.ps1. Change the file name to the one you want to examine.

Get-WmiObject -Class 'CIM_DataFile' -Filter "name='C:\\Program Files (x86)\\PuTTY\\psftp.exe'" | % { $_.Version }

Put the following into the .bat script file.

FOR /F %%v IN ('powershell -NoLogo -NoProfile -File .\veronly.ps1') DO (SET "THEVERSION=%%v")
ECHO %THEVERSION%

Upvotes: 0

npocmaka
npocmaka

Reputation: 57252

Try like this:

for /f "skip=2 delims== tokens=2" %%g in ('WMIC DATAFILE WHERE ^"Name^='!filePath!'^" GET Version /value') DO (
    for /f "tokens=* delims=" %%# in ("%%g") do set "fileVersion=%%#"
)

Upvotes: 1

Magoo
Magoo

Reputation: 79983

ECHO Version: "%fileVersion:~0,-1%"

may assist your investigations...

Upvotes: 2

Related Questions