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.
To deal with this I came up with the following batch script code
@echo off
cd %temp%
for /d %%D in (*) do rd /s /q "%%D"
del /f /q *
I have the following issues with it
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 cd %temp%
does not navigate to the temp as there is no temp folder.
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.
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.
I tried the following Runtime.getRuntime().exec("taskkill /f /im cmd.exe");
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?