TheHvidsten
TheHvidsten

Reputation: 4438

Windows batch file using ImageX info

I have a folder with several ImageX files (*.wim). I can loop through those and select one of them with the following batch file:

@echo off
setlocal enabledelayedexpansion
for %%a in (*.wim) do (
    set /a gt_i+=1
    echo !gt_i! - %%~nxa
    set gt_files[!gt_i!]=%%~fa
)
set /p m0="Select file: "
REM Do imagex applying of selected image here

This works just fine, but I would like something prettier than just the filenames.

ImageX has an option, "/info", that displays various metadata about the image in the following format:

C:\>imagex /info myfile.wim 1

ImageX Tool for Windows
Copyright (C) Microsoft Corp. All rights reserved.
Version: 6.1.7600.16385

Image Information:
------------------
<IMAGE INDEX="1">
  <DIRCOUNT>10817</DIRCOUNT>
  <FILECOUNT>57345</FILECOUNT>
  <TOTALBYTES>10790852647</TOTALBYTES>
  <HARDLINKBYTES>3603810948</HARDLINKBYTES>
  <CREATIONTIME>
    <HIGHPART>0x01CF15CB</HIGHPART>
    <LOWPART>0xF1871990</LOWPART>
  </CREATIONTIME>
  <LASTMODIFICATIONTIME>
    <HIGHPART>0x01CF3C5B</HIGHPART>
    <LOWPART>0x32F96B0C</LOWPART>
  </LASTMODIFICATIONTIME>
  <WINDOWS>
    <ARCH>0</ARCH>
    <PRODUCTNAME>Microsoft® Windows® Operating System</PRODUCTNAME>
    <EDITIONID>Embedded</EDITIONID>
    <INSTALLATIONTYPE>Embedded</INSTALLATIONTYPE>
    <HAL>acpiapic</HAL>
    <PRODUCTTYPE>WinNT</PRODUCTTYPE>
    <PRODUCTSUITE>Terminal Server</PRODUCTSUITE>
    <LANGUAGES>
      <LANGUAGE>en-US</LANGUAGE>
      <DEFAULT>en-US</DEFAULT>
    </LANGUAGES>
    <VERSION>
      <MAJOR>6</MAJOR>
      <MINOR>1</MINOR>
      <BUILD>7601</BUILD>
      <SPBUILD>17965</SPBUILD>
      <SPLEVEL>1</SPLEVEL>
    </VERSION>
    <SYSTEMROOT>WINDOWS</SYSTEMROOT>
  </WINDOWS>
  <NAME>My custom image name set during creation</NAME>
</IMAGE>

How can I use the <NAME> tag in this info from imagex instead of the filename in the for loop in the script?

This is almost the same question as this one, but I can't find a proper solution for this specific problem in it (other that I can use imagex /info myfile.wim | find "<NAME>" but that includes leading spaces as well as the actual XML tags)

Upvotes: 0

Views: 354

Answers (1)

woxxom
woxxom

Reputation: 73686

Use for /f:

@echo off
setlocal enabledelayedexpansion
for %%a in (*.wim) do (
    set /a gt_i+=1
    for /f "delims=<> tokens=3" %%b in ('imagex /info %%~nxa ^| find "<NAME>"') do set name=%%b
    echo !gt_i! - %%~nxa - !name!
    set gt_files[!gt_i!]=%%~fa
)
set /p m0="Select file: "
REM Do imagex applying of selected image here

Upvotes: 1

Related Questions