title: How to convert multiple xls files to csv using powershell?
body: <p>I'm trying to convert multiple Excel files (xls) to csv using the following powershell script:  </p>
  
  <pre><code>$excel = new-object -ComObject "Excel.Application"
  $excel.DisplayAlerts=$True
  $excel.Visible =$false
  foreach ($file in get-childitem $src_dir) {
      $wb = $excel.Workbooks.Open($file.FullName)
      $wb.SaveAs($dst_dir + $file.Name + ".csv", 6)# 6 -&gt; csv
      $wb.Close($True)
  }
  $excel.Quit()
  [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
  </code></pre>
  
  <p>In principle this works e.g. I get csv files. However, for a few files (varying per run) I get an exception:</p>
  
  <pre><code>Exception calling "SaveAs" with "2" argument(s): "Microsoft Office Excel cannot access the file 'C:\Users\...\AppData\Local\Temp'. ...
  </code></pre>
  
  <p>Additionally, I get a message box asking if I want to save the changes to the source xls.</p>
  
  <p>Once I call SaveAs, $wb references the new file. So how do I save or discard the changes to the source file? Why does this happen only for a few files? Are there any other problems with this script?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I divided the input files (ca. 200) arbitrarily (i.e. don't know the size of the groups) into 10 groups and processed each group in its own run. That worked so it is somewhat inconvenient.</p>
  
  <p>thanks in advance</p>