title: Windows: Create folder structure based on XML file
body: <p>I'm trying to find a way to create a full folder/subfolders/files(shortcuts) arborescence in Windows, based on an XML file input.</p>
  
  <p>My XML looks like this:</p>
  
  <pre><code>&lt;folder name="Folder1"&gt;
      &lt;shortcut url="http://A.com" name="A" /&gt;
      &lt;shortcut url="http://B.com" name="B" /&gt;
      &lt;folder name="1.1"&gt;
          &lt;shortcut url="http://C.com" name="C" /&gt;
      &lt;/folder&gt;
      &lt;folder name="Folder1.2"&gt;
          &lt;shortcut url="http://D.com" name="D" /&gt;
      &lt;/folder&gt;
  &lt;/folder&gt;
  &lt;folder name="Folder2"&gt;
      ...
  &lt;/folder&gt;
  </code></pre>
  
  <p>And the resulting folders would be:</p>
  
  <ul>
  <li>Folder1
  
  <ul>
  <li>A.url</li>
  <li>B.url</li>
  <li>Folder1.1
  
  <ul>
  <li>C.url</li>
  </ul></li>
  <li>Folder1.2
  
  <ul>
  <li>D.url</li>
  </ul></li>
  </ul></li>
  <li>Folder2
  
  <ul>
  <li>...</li>
  </ul></li>
  </ul>
  
  <p>-> To sum up, recursive folders/subfolders creation, plus creation of shortcuts (.url files)</p>
  
  <p>Any idea on how to do this? 
  Via cmd, powershell ?</p>
  
  <p>(if .url files creation in not possible, i'll make them manually (more than 300...) )</p>
  
  <p>Many thanks!</p>
  
  <hr/>
  
  <p>EDIT: SOLUTION</p>
  
  <p>Thanks @rojo, good direction.
  I've modified my need of creation "Shortcuts" by html files. (content truncated here, just for sample)
  I've added a target path, several errors handling (folders and files creation, by creating error txt files, easily searchable to fix manually), as well as added the creation of files at root. (not in subfolders)</p>
  
  <p>Probably not very optimized, but well...</p>
  
  <pre><code>&lt;# : Batch Portion
  @echo off &amp; setlocal
  
  powershell -noprofile -noexit -noninteractive "iex (gc \"%~f0\" | out-string)"
  goto :EOF
  
  : End Batch / begin PowerShell hybrid chimera #&gt;
  
  [xml]$DOM = gc clv.xml
  $destPath="D:\Test\Folders"
  
  function CreateShortcut([string]$target, [string]$saveLoc, [string]$fileName) {
  
  $aspxText= @"
  &lt;html&gt;
  &lt;body&gt;
  &lt;a href="$target"&gt;Target URL&lt;/a&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  "@  
  try{
  New-Item ($saveLoc+'/'+$fileName+'.aspx') -type file -value  $aspxText -ea Stop
  }
  catch{
  $err=@"
  Name:
  $fileName
  Url:
  $target
  
  Error:
  $_.Exception.GetType().FUllname
  "@
  
  New-Item ($saveLoc+'/###Error.txt') -type file -value  $txtDoc
  }
  
      write-host "$($saveLoc)\$($fileName)" -f cyan
  }
  
  cd $destPath
  function launchCreation($root){
      $rootshortcuts = @($root.shortcut)
      if($rootshortcuts -ne $null){
          foreach ($shortcut in $rootshortcuts) {
              $fixedShortcutName=$shortcut.name  -replace '[&lt;&gt;:"\/\\?\*\|]', '-'
              $urlfile = (pwd).Path
              CreateShortcut $shortcut.url $urlfile $fixedShortcutName $shortcut.isDoc $shortcut.isTaxo
          }
      }
      Walk($root)
  }
  function Walk($root) {  
      $folders = @($root.folder)
      if($folders -ne $null){
          foreach ($folder in $folders) {
              $folderName=$folder.name -replace '[&lt;&gt;:"\/\\?\*\|]', '-'
              if (-not (test-path $folderName)) {  md $folderName }
              cd $folderName
              write-host (Join-Path $destPath $folderName) -f magenta
              $shortcuts = @($folder.shortcut)
              if($shortcuts -ne $null){
                  foreach ($shortcut in $shortcuts) {
                      $fixedShortcutName=$shortcut.name  -replace '[&lt;&gt;:"\/\\?\*\|]', '-'
                      $urlfile = (pwd).Path
                      CreateShortcut $shortcut.url $urlfile $fixedShortcutName $shortcut.isDoc $shortcut.isTaxo
                  }
              }
              Walk $folder
              cd..
          }
      }
  
  }
  
  [void](launchCreation $DOM.documentElement)
  </code></pre>