コード例 #1
0
ファイル: file-util.cpp プロジェクト: 0-wiz-0/WCMCommander
bool DeleteListRecursively( FS* fs, FSPath path, FSList& list )
{
	const int cnt = path.Count();
	int ret_err;

	for ( FSNode* node = list.First(); node; node = node->next )
	{
		if ( node->extType )
		{
			continue;
		}

		path.SetItemStr( cnt, node->Name() );

		if ( node->IsDir() && !node->st.IsLnk() )
		{
			if ( !DeleteDirRecursively( fs, path ) )
			{
				return false;
			}
		}
		else if ( fs->Delete( path, &ret_err, nullptr ) != 0 )
		{
			return false;
		}
	}

	return true;
}
コード例 #2
0
ファイル: FileUtil.cpp プロジェクト: Summeli/ppsspp
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory)
{
    INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
#ifdef _WIN32
    // Find the first file in the directory.
    WIN32_FIND_DATA ffd;
    HANDLE hFind = FindFirstFile((directory + "\\*").c_str(), &ffd);

    if (hFind == INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        return false;
    }

    // windows loop
    do
    {
        const std::string virtualName = ffd.cFileName;
#else
    struct dirent dirent, *result = NULL;
    DIR *dirp = opendir(directory.c_str());
    if (!dirp)
        return false;

    // non windows loop
    while (!readdir_r(dirp, &dirent, &result) && result)
    {
        const std::string virtualName = result->d_name;
#endif

        // check for "." and ".."
        if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
                ((virtualName[0] == '.') && (virtualName[1] == '.') &&
                 (virtualName[2] == '\0')))
            continue;

        std::string newPath = directory + DIR_SEP + virtualName;
        if (IsDirectory(newPath))
        {
            if (!DeleteDirRecursively(newPath))
                return false;
        }
        else
        {
            if (!File::Delete(newPath))
                return false;
        }

#ifdef _WIN32
    }
    while (FindNextFile(hFind, &ffd) != 0);
    FindClose(hFind);
#else
    }
    closedir(dirp);
#endif
    File::DeleteDir(directory);

    return true;
}
コード例 #3
0
ファイル: file-util.cpp プロジェクト: 0-wiz-0/WCMCommander
void RemoveAllWcmTempDirs()
{
	for ( auto &iter : g_TempDirUriList )
	{
		std::vector<unicode_t> TempUri = iter.second;

		if ( TempUri.data() )
		{
			FSPath path;
			clPtr<FS> fs = ParzeURI( TempUri.data(), path, std::vector<clPtr<FS>>() );

			DeleteDirRecursively( fs.Ptr(), path );
		}
	}
}
コード例 #4
0
ファイル: file-util.cpp プロジェクト: 0-wiz-0/WCMCommander
void RemoveWcmTempDir( const int Id )
{
	auto iter = g_TempDirUriList.find( Id );

	if ( iter != g_TempDirUriList.end() )
	{
		std::vector<unicode_t> TempUri = iter->second;

		if ( TempUri.data() )
		{
			FSPath path;
			clPtr<FS> fs = ParzeURI( TempUri.data(), path, std::vector<clPtr<FS>>() );
			
			DeleteDirRecursively( fs.Ptr(), path );
		}
	}
}
コード例 #5
0
ファイル: file_util.cpp プロジェクト: Gabrielbeck/citra
bool DeleteDirRecursively(const std::string &directory)
{
    const static auto callback = [](unsigned* num_entries_out,
                                    const std::string& directory,
                                    const std::string& virtual_name) -> bool {
        std::string new_path = directory + DIR_SEP_CHR + virtual_name;
        if (IsDirectory(new_path))
            return DeleteDirRecursively(new_path);

        return Delete(new_path);
    };

    if (!ForeachDirectoryEntry(nullptr, directory, callback))
        return false;

    // Delete the outermost directory
    FileUtil::DeleteDir(directory);
    return true;
}
コード例 #6
0
ファイル: file_util.cpp プロジェクト: Christchex/XDS
bool DeleteDirRecursively(const std::string &directory)
{
    const static auto callback = [](const std::string& directory,
                                    const std::string& virtual_name) -> int {
        std::string new_path = directory + DIR_SEP_CHR + virtual_name;
        if (IsDirectory(new_path)) {
            if (!DeleteDirRecursively(new_path)) {
                return -2;
            }
        } else if (!Delete(new_path)) {
            return -2;
        }
        return 0;
    };

    if (ScanDirectoryTreeAndCallback(directory, callback) == -2) {
        return false;
    }
    FileUtil::DeleteDir(directory);

    return true;
}
コード例 #7
0
ファイル: FileUtil.cpp プロジェクト: mailwl/ppsspp
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory)
{
#if PPSSPP_PLATFORM(UWP)
	return false;
#else
	INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());

#ifdef _WIN32

	// Find the first file in the directory.
	WIN32_FIND_DATA ffd;
	HANDLE hFind = FindFirstFile(ConvertUTF8ToWString(directory + "\\*").c_str(), &ffd);

	if (hFind == INVALID_HANDLE_VALUE)
	{
		return false;
	}
		
	// windows loop
	do
	{
		const std::string virtualName = ConvertWStringToUTF8(ffd.cFileName);
#else
	struct dirent *result = NULL;
	DIR *dirp = opendir(directory.c_str());
	if (!dirp)
		return false;

	// non windows loop
	while ((result = readdir(dirp)))
	{
		const std::string virtualName = result->d_name;
#endif
		// check for "." and ".."
		if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
			((virtualName[0] == '.') && (virtualName[1] == '.') && 
			 (virtualName[2] == '\0')))
			continue;

		std::string newPath = directory + DIR_SEP + virtualName;
		if (IsDirectory(newPath))
		{
			if (!DeleteDirRecursively(newPath))
			{
#ifndef _WIN32
				closedir(dirp);
#else
				FindClose(hFind);
#endif
				return false;
			}
		}
		else
		{
			if (!File::Delete(newPath))
			{
#ifndef _WIN32
				closedir(dirp);
#else
				FindClose(hFind);
#endif
				return false;
			}
		}

#ifdef _WIN32
	} while (FindNextFile(hFind, &ffd) != 0);
	FindClose(hFind);
#else
	}
	closedir(dirp);
#endif
	return File::DeleteDir(directory);
#endif
}
コード例 #8
0
ファイル: file_util.cpp プロジェクト: Glought/citra
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory)
{
    LOG_TRACE(Common_Filesystem, "%s", directory.c_str());
#ifdef _WIN32
    // Find the first file in the directory.
    WIN32_FIND_DATA ffd;
    HANDLE hFind = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd);

    if (hFind == INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        return false;
    }

    // windows loop
    do
    {
        const std::string virtualName(Common::TStrToUTF8(ffd.cFileName));
#else
    struct dirent dirent, *result = nullptr;
    DIR *dirp = opendir(directory.c_str());
    if (!dirp)
        return false;

    // non windows loop
    while (!readdir_r(dirp, &dirent, &result) && result)
    {
        const std::string virtualName = result->d_name;
#endif

        // check for "." and ".."
        if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
            ((virtualName[0] == '.') && (virtualName[1] == '.') &&
             (virtualName[2] == '\0')))
            continue;

        std::string newPath = directory + DIR_SEP_CHR + virtualName;
        if (IsDirectory(newPath))
        {
            if (!DeleteDirRecursively(newPath))
            {
                #ifndef _WIN32
                closedir(dirp);
                #endif

                return false;
            }
        }
        else
        {
            if (!FileUtil::Delete(newPath))
            {
                #ifndef _WIN32
                closedir(dirp);
                #endif

                return false;
            }
        }

#ifdef _WIN32
    } while (FindNextFile(hFind, &ffd) != 0);
    FindClose(hFind);
#else
    }
    closedir(dirp);
#endif
    FileUtil::DeleteDir(directory);

    return true;
}
コード例 #9
0
ファイル: FileUtil.cpp プロジェクト: Anti-Ultimate/dolphin
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string& directory)
{
  INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
  bool success = true;

#ifdef _WIN32
  // Find the first file in the directory.
  WIN32_FIND_DATA ffd;
  HANDLE hFind = FindFirstFile(UTF8ToTStr(directory + "\\*").c_str(), &ffd);

  if (hFind == INVALID_HANDLE_VALUE)
  {
    FindClose(hFind);
    return false;
  }

  // Windows loop
  do
  {
    const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
  DIR* dirp = opendir(directory.c_str());
  if (!dirp)
    return false;

  // non Windows loop
  while (dirent* result = readdir(dirp))
  {
    const std::string virtualName = result->d_name;
#endif

    // check for "." and ".."
    if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
        ((virtualName[0] == '.') && (virtualName[1] == '.') && (virtualName[2] == '\0')))
      continue;

    std::string newPath = directory + DIR_SEP_CHR + virtualName;
    if (IsDirectory(newPath))
    {
      if (!DeleteDirRecursively(newPath))
      {
        success = false;
        break;
      }
    }
    else
    {
      if (!File::Delete(newPath))
      {
        success = false;
        break;
      }
    }

#ifdef _WIN32
  } while (FindNextFile(hFind, &ffd) != 0);
  FindClose(hFind);
#else
  }
  closedir(dirp);
#endif
  if (success)
    File::DeleteDir(directory);

  return success;
}