Exemple #1
0
bool cceDirRemoverHelper::RecursiveRemoveDir(QDir aDir)
{
	bool allOk = true;
	if (aDir.exists())//QDir::NoDotAndDotDot
		{
			QFileInfoList entries = aDir.entryInfoList(	QDir::NoDotAndDotDot |
																									QDir::Dirs |
																									QDir::Files);
			foreach (QFileInfo entryInfo, entries)
				{
					QString path = entryInfo.absoluteFilePath();
					if (entryInfo.isDir())
						{
							allOk = RecursiveRemoveDir(QDir(path));
						}
					else
						{
							QFile file(path);
							if (!file.remove())
								{
									allOk = false;
								}
						}
					if (!allOk)
						{
							break;
						}
				}
Exemple #2
0
BOOL
RemoveDirectoryPath (LPCWSTR lpPathName)
{
  if (!RecursiveRemoveDir (lpPathName))
    return FALSE;

  DPRINT ("Delete directory: '%S'\n", lpPathName);
  return RemoveDirectoryW (lpPathName);
}
Exemple #3
0
static BOOL
RecursiveRemoveDir (LPCWSTR lpPath)
{
  WCHAR szPath[MAX_PATH];
  WIN32_FIND_DATAW FindData;
  HANDLE hFind;
  BOOL bResult;

  wcscpy (szPath, lpPath);
  wcscat (szPath, L"\\*.*");
  DPRINT ("Search path: '%S'\n", szPath);

  hFind = FindFirstFileW (szPath,
			  &FindData);
  if (hFind == INVALID_HANDLE_VALUE)
    return FALSE;

  bResult = TRUE;
  while (TRUE)
    {
      if (wcscmp (FindData.cFileName, L".") &&
	  wcscmp (FindData.cFileName, L".."))
	{
	  wcscpy (szPath, lpPath);
	  wcscat (szPath, L"\\");
	  wcscat (szPath, FindData.cFileName);
	  DPRINT ("File name: '%S'\n", szPath);

	  if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
	    {
	      DPRINT ("Delete directory: '%S'\n", szPath);

	      if (!RecursiveRemoveDir (szPath))
		{
		  bResult = FALSE;
		  break;
		}

	      if (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
		{
		  SetFileAttributesW (szPath,
				      FindData.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
		}

	      if (!RemoveDirectoryW (szPath))
		{
		  bResult = FALSE;
		  break;
		}
	    }
	  else
	    {
	      DPRINT ("Delete file: '%S'\n", szPath);

	      if (FindData.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
		{
		  SetFileAttributesW (szPath,
				      FILE_ATTRIBUTE_NORMAL);
		}

	      if (!DeleteFileW (szPath))
		{
		  bResult = FALSE;
		  break;
		}
	    }
	}

      if (!FindNextFileW (hFind, &FindData))
	{
	  if (GetLastError () != ERROR_NO_MORE_FILES)
	    {
	      DPRINT1 ("Error: %lu\n", GetLastError());
	      bResult = FALSE;
	      break;
	    }

	  break;
	}
    }

  FindClose (hFind);

  return bResult;
}