MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / DeleteDirectory

Method DeleteDirectory

cpp/iedriver/BrowserFactory.cpp:1543–1587  ·  view source on GitHub ↗

delete a folder recursively

Source from the content-addressed store, hash-verified

1541
1542// delete a folder recursively
1543int BrowserFactory::DeleteDirectory(const std::wstring &dir_name) {
1544 WIN32_FIND_DATA file_info;
1545
1546 std::wstring file_pattern = dir_name + L"\\*.*";
1547 HANDLE file_handle = ::FindFirstFile(file_pattern.c_str(), &file_info);
1548 if (file_handle != INVALID_HANDLE_VALUE) {
1549 do {
1550 if (file_info.cFileName[0] == '.') {
1551 continue;
1552 }
1553 std::wstring file_path = dir_name + L"\\" + file_info.cFileName;
1554
1555 if (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1556 int return_value = DeleteDirectory(file_path);
1557 if (return_value) {
1558 return return_value;
1559 }
1560 } else {
1561 if (::SetFileAttributes(file_path.c_str(), FILE_ATTRIBUTE_NORMAL) == FALSE) {
1562 return ::GetLastError();
1563 }
1564
1565 if (::DeleteFile(file_path.c_str()) == FALSE) {
1566 return ::GetLastError();
1567 }
1568 }
1569 } while (::FindNextFile(file_handle, &file_info) == TRUE);
1570
1571 ::FindClose(file_handle);
1572 DWORD dwError = ::GetLastError();
1573 if (dwError != ERROR_NO_MORE_FILES) {
1574 return dwError;
1575 }
1576
1577 if (::SetFileAttributes(dir_name.c_str(), FILE_ATTRIBUTE_NORMAL) == FALSE) {
1578 return ::GetLastError();
1579 }
1580
1581 if (::RemoveDirectory(dir_name.c_str()) == FALSE) {
1582 return ::GetLastError();
1583 }
1584 }
1585
1586 return 0;
1587}
1588
1589std::wstring BrowserFactory::GetEdgeTempDir() {
1590 return this->edge_user_data_dir_;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected