/// <summary> /// 获取文件总数 /// </summary> /// <returns></returns> public void GetFileNumber(string dir, ref int fileNumber) { string[] arrDir = Directory.GetDirectories(dir); for (int i = 0; i < arrDir.Length; i++) { // 跳过忽略目录 string currentDirName = GetDirectoryNameByPath(arrDir[i]).ToLower(); if (IgnoreDir.Contains(currentDirName)) { if (currentDirName == "upload") { string[] arrUploadChildDir = Directory.GetDirectories(arrDir[i]); for (int j = 0; j < arrUploadChildDir.Length; j++) { string currentUploadChildDir = GetDirectoryNameByPath(arrUploadChildDir[j]).ToLower(); if (currentUploadChildDir == "initialize" || currentUploadChildDir == "site") { GetFileNumber(arrUploadChildDir[j], ref fileNumber); } else { continue; } } } continue; } // 递归 GetFileNumber(arrDir[i], ref fileNumber); } string[] file = Directory.GetFiles(dir); for (int i = 0; i < file.Length; i++) { FileInfo fi = new FileInfo(file[i]); if (!IgnoreFileSuffix.Contains(fi.Extension.ToLower()) && !IgnoreFileName.Contains(fi.Name.ToLower())) { fileNumber++; } } }
/// <summary> /// 生成版本文件 /// </summary> /// <param name="dir"></param> public string GenerateVersionStr(string dir) { string[] file = Directory.GetFiles(dir); string fileContent = string.Empty; foreach (var item in file) { string suffix = item.Substring(item.LastIndexOf(".") + 1); if (!IgnoreFileSuffix.Contains(suffix)) { string hashValue = GetMD5HashFromFile(item); fileContent += $"{item}={hashValue}\r\n"; } } string[] chidrenDir = Directory.GetDirectories(dir); foreach (var item in chidrenDir) { if (!IgnoreDir.Contains(item)) { fileContent += GenerateVersionStr(item); } } return(fileContent); }