Folder is being used by some process. How to find the process?
Such a nasty issue may happen to everyone: you want to delete the folder, but you can’t, because it is being used by an other process. The following C# code shows how to find this process, which you may want to terminate later on.
- Download sysinternals-suite from microsoft
- Find a path to handle.exe in sysinternals-suite
- Run C# code
// Define the path of the folder you want to delete string folderPath = @"C:\[YOUR_FOLDER]"; // Run the Handle tool to find out which process is using the folder Process handleProcess = Process.Start(new ProcessStartInfo { FileName = "C:\\[PATH_TO_HANDLE]\\handle.exe", Arguments = $"-accepteula {folderPath}", UseShellExecute = false, RedirectStandardOutput = true }); // Read the output of the Handle tool string output = handleProcess.StandardOutput.ReadToEnd(); // Display the output Console.WriteLine(output);