2016-03-04 80 views
-1

樣本文件的XML 1個如何獲得多個xml文件的相同值,然後使用powershell命令創建一個文件夾?

enter code here 
<?xml version="1.0"?> 
<catalog> 
<book id="bk101"> 
    <author>Gambardella, Matthew</author> 
    <title>XML Developer's Guide</title>` 
    <genre>Test1</genre> 
    <price>44.95</price> 
    <publish_date>2000-10-01</publish_date> 
    <description>An in-depth look at creating applications 
    with XML.</description> 

樣本文件的XML 2

enter code here 
<?xml version="1.0"?> 
<catalog> 
<book id="bk101"> 
    <author>Gambardella, Matthew</author> 
    <title>XML Developer's Guide</title> 
    <genre>Test2</genre> 
    <price>44.95</price> 
    <publish_date>2000-10-01</publish_date> 
    <description>An in-depth look at creating applications 
    with XML.</description> 

需要得到 「流派」,然後創建每個文件夾的價值?

+2

你能解釋你在這裏嘗試做什麼好一點? [本頁](https://stackoverflow.com/help/how-to-ask)在編寫一個好問題上有一些很棒的提示。 –

回答

1

隨着移動文件的一部分:

Get-ChildItem *.xml | % { 
      [xml]$x=get-content $_ ; 
      $newpath=$x.catalog.book.genre 
      new-item "$newpath"-type Directory -ErrorAction SilentlyContinue 
      if (test-path "$newpath") { 
       move-item "$_" -destination "$newpath" 
      } 
      } 
0

我知道你想用XML發現每一個流派目錄中的文件的話,如果你有每個文件的一本書:

Get-ChildItem *.xml | % { [xml]$x=get-content $_ ;new-item $x.catalog.book.genre -type Directory -ErrorAction SilentlyContinue } 
+0

然後,我需要將文件移動到該文件夾​​中。請幫助..謝謝 sample file.xml 1 ---> Test1 sample file.xml 2 ---> test2 – thenoid

相關問題