private static void DeleteFileAndEmptyDir(FileInfo file, int depth) { if (!file.Exists) return; file.Delete(); file.Refresh(); if (file.Exists) { throw new IOException("File cannot be deleted: " + file); } DeleteEmptyDir(file.Directory, depth); }