/// <summary> /// 删除指定名称的文件 /// 会处理相关的相对路径 /// </summary> /// <param name="path">搜索的目录</param> /// <param name="versionName">一般是平台名字,也可以加其他文件夹在</param> /// <param name="fileNames">需要删除的文件名字,相对路径,斜杠为/</param> private static void DeleteAssetBundleFiles(string path, string versionName, Dictionary <string, string> fileNames) { DirectoryInfo fileDir = new DirectoryInfo(path); FileInfo[] files = fileDir.GetFiles(); foreach (var file in files) { //绝对路径转换为相对路径,并且转换为UNIX的斜杠‘/’ var abpi = ABSH.GetAssetBundleOutputPath(versionName); //路径里可千万别有相同的目录结构啊……比如 Assets/AssetBundles/Windows64/XXXXXX/Assets/AssetBundles/Windows64/ int index = file.FullName.LastIndexOf(abpi.Dir_Relative) + abpi.Dir_Relative.Length + 1; if (index >= 0) { if (index < file.FullName.Length) { var relativePath = AssetBundleSettingHelper.PathToPlatformFormat(file.FullName.Substring(index)); //Debug.Log(relativePath); if (fileNames.ContainsKey(relativePath.ToLower())) { DeleteFileAndManifest(file.FullName); } } else { Debug.LogError("DeleteAssetBundleFiles Error:" + file.FullName + " :abpi.Dir_Relative:" + abpi.Dir_Relative); } } } var dirs = fileDir.GetDirectories(); foreach (var dir in dirs) { //递归调用 DeleteAssetBundleFiles(dir.FullName, versionName, fileNames); } }