0

I am struggling and wondered if someone could help me...

I have many folders and each one will have a large xml file in it. I would to recurse through my folders and find my xml file. Once I have this xml I would like to pull some values from the xml and create a folder on a web server with a version subfolder and then copy a jpg file to it from the parent folder. So far I can get a single xml and return all the values of a field but cannot get it to create the folders based on the value. Would be nice if the script ignores if the folder exists. My xml would look something like this...

DATA

  • ASSET

    • PART
      • Version "1"
      • partnumber "ABC123"
      • CAR
        • make "FORD"
        • colour "BLACK.JPG"
      • CAR
        • make "FERRARI"
        • colour "RED.JPG"

so the result should be folder structure like this

ABC123\

   1\
     FORD\
          black.jpg
     FERRARI\
           red.jpg

Apologies for the poor quality of the data in the post, first time posting and I couldn't get it to work

4

1 回答 1

1

这是可能的方法:

$xml = [xml]@'
<Data>
  <Asset>
    <Part version="1" partnumber="ABC123">
      <Car make="Ford" colour="Black.jpg"/>
      <Car make="Ferrari" colour="Red.jpg"/>
    </Part>
  </Asset>
</Data>
'@

$xmlPath = "C:\foo"
$pathRoot = "\\server\share\"
foreach ($part in $xml.Data.Asset.Part)
{
    $dir = $part.partnumber
    mkdir $pathRoot\$dir -WhatIf
    foreach ($car in $part.Car)
    {
        $dir = Join-Path $dir $car.make
        mkdir $pathRoot\$dir -WhatIf
        $colour = $car.colour
        Copy-Item $xmlPath\$dir\$colour $pathRoot\$dir\$colour -WhatIf
    }
}

$xmlPath 将指向包含 xml 文件的目录。我认为那是您可以从中复制 jpg 文件的地方。

于 2013-05-08T02:41:56.327 回答