public static List <SKFileInfo> GetSKFileInfoList_ByRootNode(XmlNode rootNode) { List <SKFileInfo> reuslt = new List <SKFileInfo>(); //传入的节点为根节点 XmlNodeList xmlNodeList = rootNode.ChildNodes; //获取所有子节点 foreach (XmlNode xn in xmlNodeList) { XmlElement xe = (XmlElement)xn; SKFileInfo Info = new SKFileInfo(); Info.name = xe.Attributes["name"].Value; Info.fileversion = xe.Attributes["fileversion"].Value; Info.productversion = xe.Attributes["productversion"].Value; Info.path = xe.Attributes["path"].Value; Info.createtime = xe.Attributes["createtime"].Value; Info.modifytime = xe.Attributes["modifytime"].Value; Info.description = xe.Attributes["description"].Value; Info.size = xe.Attributes["size"].Value; Info.type = xe.Attributes["type"].Value; Info.remark = xe.Attributes["remark"].Value; reuslt.Add(Info); } return(reuslt); }
/// <summary> /// 获取文件信息列表 /// </summary> /// <param name="fileinfos">系统文件列表</param> /// <returns></returns> public static List <SKFileInfo> GetSKFileInfoList(FileInfo[] fileinfos, List <string> IgnoreFileList, string RelativePath = "") { List <SKFileInfo> reuslt = new List <SKFileInfo>(); //前提:确保FileInfo中没有文件夹否则将无法获取文件夹内的信息 FileInfo[] fileInfo = fileinfos; for (int i = 0; i < fileInfo.Length; i++) { bool isAdd = true; if (IgnoreFileList != null) { foreach (string s in IgnoreFileList) { if (fileInfo[i].Name == s) { isAdd = false; break; } } if (!isAdd) { continue; } } SKFileInfo ClientInfo = GetSKFileInfo(fileInfo[i], RelativePath); if (ClientInfo != null) { reuslt.Add(ClientInfo); } } return(reuslt); }
/// <summary> /// 获取文件信息 /// </summary> /// <param name="fileinfo">文件信息</param> /// <param name="RelativePath">相对路径</param> /// <returns></returns> public static SKFileInfo GetSKFileInfo(FileInfo fileinfo, string RelativePath) { SKFileInfo result = new SKFileInfo(); //如果相对路径为空返回的文件信息为绝对路径,否则为相对路径 FileInfo fileInfo = fileinfo; // 如果文件存在 if (fileInfo != null && fileInfo.Exists) { FileVersionInfo info = FileVersionInfo.GetVersionInfo(fileInfo.FullName); result.name = fileInfo.Name; if (info.FileVersion == null) { result.fileversion = " "; } else { result.fileversion = info.FileVersion; } if (info.ProductVersion == null) { result.productversion = " "; } else { result.productversion = info.ProductVersion; } if (RelativePath == "") { result.path = fileInfo.FullName; } else { result.path = fileInfo.FullName.Replace(RelativePath + @"\", "").Replace(@"\", "/"); //绝对路径中的初始路径改为 . 形成相对路径 } result.createtime = fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"); result.modifytime = fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); if (info.FileDescription == null) { result.description = " "; } else { result.description = info.FileDescription; } result.size = fileInfo.Length.ToString(); result.type = "1"; result.remark = " "; } else { } // 末尾空一行 //Console.WriteLine(); //return clientInfo; return(result); }
/// <summary> /// 获取文件信息 /// </summary> /// <param name="strFilePath">文件地址</param> /// <returns></returns> public static SKFileInfo GetSKFileInfo(string strFilePath) { SKFileInfo result = new SKFileInfo(); FileInfo fileInfo = new FileInfo(strFilePath); if (fileInfo != null && fileInfo.Exists) { FileVersionInfo info = FileVersionInfo.GetVersionInfo(fileInfo.FullName); result.name = fileInfo.Name; if (info.FileVersion == null) { result.fileversion = " "; } else { result.fileversion = info.FileVersion; } if (info.ProductVersion == null) { result.productversion = " "; } else { result.productversion = info.ProductVersion; } //result.path = fileInfo.FullName.Replace(Path, "."); //绝对路径中的初始路径改为 .. 形成相对路径 result.path = fileInfo.FullName; result.createtime = fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"); result.modifytime = fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); if (info.FileDescription == null) { result.description = " "; } else { result.description = info.FileDescription; } result.size = fileInfo.Length.ToString(); result.type = "1"; result.remark = " "; } return(result); }
/// <summary> /// 获取文件信息 /// </summary> /// <param name="node">节点信息</param> /// <returns></returns> public static SKFileInfo GetSKFileInfo(XmlNode node) { //节点为元素类型,即一个元素占一个属性 SKFileInfo result = new SKFileInfo(); XmlNodeList xmlNodeList = node.ChildNodes; //获取所有子节点 result.name = xmlNodeList[0].InnerText; result.fileversion = xmlNodeList[1].InnerText; result.productversion = xmlNodeList[2].InnerText; result.path = xmlNodeList[3].InnerText; result.createtime = xmlNodeList[4].InnerText; result.modifytime = xmlNodeList[5].InnerText; result.description = xmlNodeList[6].InnerText; result.size = xmlNodeList[7].InnerText; result.type = xmlNodeList[8].InnerText; result.remark = xmlNodeList[9].InnerText; return(result); }
/// <summary> /// 获取文件信息 /// </summary> /// <param name="element">节点属性</param> /// <returns></returns> public static SKFileInfo GetSKFileInfo(XmlElement element) { SKFileInfo result = new SKFileInfo(); //由单元素获取此元素内的文件信息 result.name = element.Attributes["name"].Value; result.fileversion = element.Attributes["fileversion"].Value; result.productversion = element.Attributes["productversion"].Value; result.path = element.Attributes["path"].Value; result.createtime = element.Attributes["createtime"].Value; result.modifytime = element.Attributes["modifytime"].Value; result.description = element.Attributes["description"].Value; result.size = element.Attributes["size"].Value; result.type = element.Attributes["type"].Value; result.remark = element.Attributes["remark"].Value; return(result); }