title: Using Batch script to clear temp folder in selenium tests
body: <p>Running a lot of selenium tests causes the temp folder to be filled up with lot 'anonymous-web-driver' profiles in the case of firefox and 'scoped-dirs' in the case of chrome.</p>
  
  <p>To deal with this I came up with the following batch script code </p>
  
  <pre><code>@echo off
  cd %temp%
  for /d %%D in (*) do rd /s /q "%%D"
  del /f /q *
  </code></pre>
  
  <p>I have the following issues with it </p>
  
  <p>1) It does the job successfully but when the batch script is run on a network drive, it deletes all the files in the current folder since <code>cd %temp%</code> does not navigate to the temp as there is no temp folder.</p>
  
  <p>Is there anyway to ensure that lines 3 and 4 are executed only when the current directory is temp. Since the script is stored on a network drive I want to ensure that even if it is run by accident it does cause any unintentional deletion.</p>
  
  <p>2) Since some of the folders cannot be deleted in the temp , the cmd window hangs there saying that these folders could not be deleted.I am fine with the files that cannot be deleted but I want to close the cmd window since I have hundreds of tests to run and each test opening up a cmd window is pretty ugly.</p>
  
  <p>I tried the following <code>Runtime.getRuntime().exec("taskkill /f /im cmd.exe");</code> and it works fine except for the following fact that it kills all cmd processes there are other cmd processes that does some work.Are there ways by which I can close only the cmd window opened by the runtime exec call?</p>