title: Batch Script - create an .XML file - name based on every .DWG file in folder
body: <p>I'd like to create a Batch file that would search a folder and create .XML files based on the .DWG file names.  It would also add the file name to (2) difference locations within the .XML (see below).</p>
  
  <p>Process:</p>
  
  <ol>
  <li>A folder contains (100) .DWG files numbered A1.dwg ~ A100.dwg</li>
  <li>The Batch file would find these file names and create the corresponding .XML file</li>
  <li>Within the .XML file (2) lines would be edited based on the file name</li>
  </ol>
  
  <p>XML Contents for file "A26":</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;File Name="A26"&gt;&lt;Version&gt;1&lt;/Version&gt;&lt;Description&gt;A26&lt;/Description&gt;&lt;Region&gt;&lt;Cell Level="1" Division="1"/&gt;&lt;Cell Level="1" Division="1"/&gt;&lt;/Region&gt;&lt;/File&gt;
  </code></pre>
  
  <p>XML Contents for file "A42":</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;File Name="A42"&gt;&lt;Version&gt;1&lt;/Version&gt;&lt;Description&gt;A42&lt;/Description&gt;&lt;Region&gt;&lt;Cell Level="2" Division="1"/&gt;&lt;Cell Level="2" Division="1"/&gt;&lt;/Region&gt;&lt;/File&gt;
  </code></pre>
  
  <p>XML Contents for file "A74":</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;File Name="A74"&gt;&lt;Version&gt;1&lt;/Version&gt;&lt;Description&gt;A74&lt;/Description&gt;&lt;Region&gt;&lt;Cell Level="3" Division="1"/&gt;&lt;Cell Level="3" Division="1"/&gt;&lt;/Region&gt;&lt;/File&gt;
  </code></pre>
  
  <p>I was able to put together the following based on another inquiry, however, it's not working for me... anything you can offer would be much appreciated.</p>
  
  <p>BTW, <code>"targetdir=C:\USC VILLAGE"</code> is the location I'm trying to output these files, but I'd like to be able to edit this path and create these files anywhere if possible.</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL
  SET "targetdir=C:\USC VILLAGE"
  SET /a filecount=0
  SET "and_subdirs="
  :again
  PUSHD "%targetdir%"
  FOR %and_subdirs% %%a IN (
    "*.dwg"
   ) DO (
    SET /a filecount+=1
    &gt;"%%~dpna.xml" (
     ECHO(^&lt;?xml version="1.0" encoding="UTF-8"?&gt;
     ECHO(         &lt;File Name="%%~na"&gt;
     ECHO(         &lt;Version&gt;1&lt;/Version&gt;
     ECHO(         &lt;Description&gt;%%~nxa"&lt;/Description&gt;
     ECHO(         &lt;/File^&gt;
    )
    )
    )
  )
  popd
  IF NOT DEFINED and_subdirs IF %filecount%==0 SET "and_subdirs=/r"&amp; GOTO again
  ECHO(%filecount% files found
  IF DEFINED and_subdirs ECHO(Subdirectories were scanned
  
  GOTO :EOF
  </code></pre>
  
  <p>Thanks,
  DOrtega</p>