static void Main(string[] args) { List <FileInformation> list = DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(@"D:\BaiduYunDownload\01-javascript(8天)")); foreach (var item in list) { Console.WriteLine(string.Format("文件名:{0}---文件目录{1}", item.FileName, item.FilePath)); } Console.ReadKey(); }
public void ClearList() { //防止重复加载 videoList.Clear(); DirectoryAllFiles.ClearList(); for (int i = 0; i < videoDataContent.childCount; i++) { Destroy(videoDataContent.GetChild(i).gameObject); } }
/// <summary> /// /// </summary> private void PreviewFiles() { this.Invoke((EventHandler)(delegate { txtFolder.Enabled = false; txtAddExtension.Enabled = false; btnGo.Enabled = false; btnPreview.Enabled = false; btnAddExtension.Enabled = false; btnDeleteExtension.Enabled = false; btnSelectAllExtension.Enabled = false; btnSelectNotAllExtension.Enabled = false; chkIncludeFolders.Enabled = false; lstViewFileInfoView.Items.Clear(); chklstExtension.Items.Clear(); int filesCount = 0; if (chkIncludeFolders.Checked) { List <FileInformation> list = new List <FileInformation>(); list = DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(@txtFolder.Text.Trim())); foreach (var item in list) { if (!chklstExtension.Items.Contains(item.FileExtension.ToLower())) //不存在,添加 { chklstExtension.Items.Add(item.FileExtension.ToLower()); } filesCount++; AddItem2ListView(lstViewFileInfoView, filesCount, item.FileExtension, item.FileName, "", item.FileDirectory); } } else { DirectoryInfo di = new DirectoryInfo(txtFolder.Text.Trim()); FileInfo[] fis = di.GetFiles(); foreach (FileInfo fi in fis) { if (!chklstExtension.Items.Contains(fi.Extension.ToLower())) //不存在,添加 { chklstExtension.Items.Add(fi.Extension.ToLower()); } filesCount++; AddItem2ListView(lstViewFileInfoView, filesCount, fi.Extension, fi.Name, "", fi.DirectoryName); } } })); }
public void InitVideoList() { List <FileInformation> list = DirectoryAllFiles.GetAllFiles(new DirectoryInfo(@"/sdcard/DCIM/Camera")); ////C:\Users\hp\Desktop\Debug var query = from file in list where file.FileName.ToLower().Contains("vid") ////qq select file; foreach (var file in query) { Debug.Log(string.Format("文件名:{0}---文件目录{1}", file.FileName, file.FilePath)); filePathText.text = ""; filePathText.text += file.FileName + "\r\n"; videoList.Add(file); } }
void Start() { List <FileInformation> list = DirectoryAllFiles.GetAllFiles(new DirectoryInfo(@"C:\Users\hp\Desktop\Debug")); var query = from file in list where file.FileName.ToLower().Contains("qq") select file; foreach (var file in query) { Debug.Log(string.Format("文件名:{0}---文件目录{1}", file.FileName, file.FilePath)); } //if (list.Where(t => t.FileName.ToLower().Contains("qq")).Any()) //{ // Debug.Log("true"); //} //foreach (var item in list) //{ // Debug.Log(string.Format("文件名:{0}---文件目录{1}", item.FileName, item.FilePath)); //} }
private void RenameFiles() { this.Invoke((EventHandler)(delegate { txtFolder.Enabled = false; txtAddExtension.Enabled = false; chkIncludeFolders.Enabled = false; btnGo.Enabled = false; btnPreview.Enabled = false; btnAddExtension.Enabled = false; btnDeleteExtension.Enabled = false; btnSelectAllExtension.Enabled = false; btnSelectNotAllExtension.Enabled = false; grbSetting.Enabled = false; lstViewFileInfoView.Items.Clear(); long filesCount = 0; if (chkIncludeFolders.Checked) //包含子文件夹 { List <FileInformation> list = new List <FileInformation>(); list = DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(@txtFolder.Text.Trim())); foreach (var item in list) { if (lstExtension.Items.Count > 0) //需要判断扩展名 { for (int i = 0; i < lstExtension.Items.Count; i++) //遍历扩展名 { if (item.FileExtension.ToLower() == lstExtension.Items[i].ToString().ToLower()) //扩展名满足要求 { string newName = CheckFilesName(item.FileName); if (!string.IsNullOrEmpty(newName) && (newName != item.FileName) && (File.Exists(item.FilePath))) { try { filesCount++; this.Text = "正在处理第:" + filesCount + "个文件"; File.Move(item.FilePath, item.FileDirectory + @"\" + newName); AddItem2ListView(lstViewFileInfoView, filesCount, item.FileExtension, item.FileName, newName, item.FileDirectory); } catch (Exception ex) { MessageBox.Show("修改文件名出现错误," + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else { string newName = CheckFilesName(item.FileName); if (!string.IsNullOrEmpty(newName) && (newName != item.FileName) && (File.Exists(item.FilePath))) { try { filesCount++; this.Text = "正在处理第:" + filesCount + "个文件"; File.Move(item.FilePath, item.FileDirectory + @"\" + newName); AddItem2ListView(lstViewFileInfoView, filesCount, item.FileExtension, item.FileName, newName, item.FileDirectory); } catch (Exception ex) { MessageBox.Show("修改文件名出现错误," + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else //不包含子文件夹 { DirectoryInfo di = new DirectoryInfo(txtFolder.Text.Trim()); FileInfo[] fis = di.GetFiles(); foreach (FileInfo fi in fis) { if (lstExtension.Items.Count > 0) { for (int i = 0; i < lstExtension.Items.Count; i++) //遍历扩展名 { if (fi.Extension.ToLower() == lstExtension.Items[i].ToString().ToLower()) { string newName = CheckFilesName(fi.Name); if ((newName != fi.Name) && !string.IsNullOrEmpty(newName) && fi.Exists) { try { filesCount++; this.Text = "正在处理第:" + filesCount + "个文件"; File.Move(fi.FullName, fi.DirectoryName + @"\" + @newName); AddItem2ListView(lstViewFileInfoView, filesCount, fi.Extension, fi.Name, newName, fi.DirectoryName); } catch (Exception ex) { MessageBox.Show("修改文件名出现错误," + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else { string newName = CheckFilesName(fi.Name); if ((newName != fi.Name) && !string.IsNullOrEmpty(newName) && fi.Exists) { try { filesCount++; this.Text = "正在处理第:" + filesCount + "个文件"; File.Move(fi.FullName, fi.DirectoryName + @"\" + @newName); AddItem2ListView(lstViewFileInfoView, filesCount, fi.Extension, fi.Name, newName, fi.DirectoryName); } catch (Exception ex) { MessageBox.Show("修改文件名出现错误," + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } MessageBox.Show("共计完成修改文件个数:" + filesCount, "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); })); }
private void btnStart_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtFolder.Text.Trim())) { updateMessage(lstInfo, "文件夹地址为空,请重新选择."); txtFolder.Focus(); return; } if (!Directory.Exists(txtFolder.Text.Trim())) { updateMessage(lstInfo, "文件夹地址不存在,请重新输入."); txtFolder.SelectAll(); txtFolder.Focus(); return; } lstInfo.Items.Clear(); long filecount = 0; List <FileInformation> list = new List <FileInformation>(); list = DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(@txtFolder.Text.Trim())); foreach (var item in list) { //FIlE0001类 string newname = string.Empty; if (item.FileName.ToLower().Trim().Contains("file")) { try { string[] temp = item.FilePath.Split('\\'); newname = temp[temp.Length - 3] + "@" + temp[temp.Length - 2] + "_" + item.FileName.ToLower().Replace("file", ""); } catch (Exception ex) { WriteLog(item.FilePath + " 文件名异常"); } // File.Move(item.FilePath, item.FileDirectory + @"\" + newname); } // if (item.FileName.Contains("_") && !item.FileName.Contains("@")) { string[] tempfile = item.FileName.Replace(item.FileExtension, "").Split('_'); if (tempfile.Length == 5) //H_20170817013502_CT00000_123456_0001 { try { string[] temp = item.FilePath.Split('\\'); newname = temp[temp.Length - 3] + "@" + tempfile[1] + "_" + tempfile[tempfile.Length - 1] + item.FileExtension; } catch (Exception ex) { WriteLog(item.FilePath + " 文件名异常"); } // File.Move(item.FilePath, item.FileDirectory + @"\" + newname); } if (tempfile.Length == 3) { if (tempfile[tempfile.Length - 1].Length == 5) //8176162_20180513043852_00011 { try { string[] temp = item.FilePath.Split('\\'); newname = temp[temp.Length - 3] + "@" + tempfile[1] + "_" + tempfile[tempfile.Length - 1].Substring(1, 4) + item.FileExtension; } catch (Exception) { WriteLog(item.FilePath + " 文件名异常"); } } if (tempfile[tempfile.Length - 1].Length == 4) //J800000_00000020170730100947_0016 { if (tempfile[1].ToLower().StartsWith("hda") | tempfile[1].ToLower().StartsWith("a")) //20181210173000_HDA00N_0011 20181210173000_A0001N_0011 { try { string[] temp = item.FilePath.Split('\\'); newname = temp[temp.Length - 3] + "@" + tempfile[0] + "_" + tempfile[tempfile.Length - 1] + item.FileExtension; // MessageBox.Show(newname); } catch (Exception) { WriteLog(item.FilePath + " 文件名异常"); } } else { try { string[] temp = item.FilePath.Split('\\'); newname = temp[temp.Length - 3] + "@" + tempfile[1].Substring(6, 14) + "_" + tempfile[tempfile.Length - 1] + item.FileExtension; } catch (Exception) { WriteLog(item.FilePath + " 文件名异常"); } } } } } if (!string.IsNullOrEmpty(newname) && !File.Exists(newname)) { try { filecount++; updateMessage(lstInfo, "正在处理:" + item.FileName); Application.DoEvents(); File.Move(item.FilePath, item.FileDirectory + @"\" + newname); } catch (Exception ex) { updateMessage(lstInfo, ex.Message); } } } MessageBox.Show("处理完毕,共计处理:" + filecount + "个文件"); }
public string ScanAllhtml(string clientInf) { Eva.Library.Data.AccessDataTrans.IAccessDataTrans t = null; Dictionary <string, string> resultDic = new Dictionary <string, string>(); resultDic["result"] = ""; resultDic["message"] = ""; try { string rootpath = Eva.Library.Format.FormatTextTool.GetMapPath(Eva.Library.Configuration.ConfigurationManager.AppSettings["AppResourceRootPath"].ToString() + "html/", Server); List <FileInformation> activeFile = new List <FileInformation>(); List <FileInformation> allFile = DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(rootpath)); #region 剔除不必要的文件 foreach (var item in allFile) { if (item.FilePath.IndexOf("lib\\framework7\\kitchen-sink-material") > -1 && (item.FileExtName == ".html" || item.FileExtName == ".json" || item.FileExtName == ".php")) { } else if (item.FilePath.IndexOf("lib\\hello-mui") > -1) { } else if (item.FileName.Contains(".min.")) { } else if (item.FileExtName == ".html" || item.FileExtName == ".js" || item.FileExtName == ".css") { activeFile.Add(item); } } #endregion sara.dd.ldsw.dal.tbl_app_version_html dal = new sara.dd.ldsw.dal.tbl_app_version_html(); t = sara.dd.ldsw.commonclass.commonclass.CreateIAccessDataTrans(); t.getTrans().begin(); System.Data.DataTable dt = dal.GetDataTableForPC("", "", "sys_id,f_htmlname,f_htmlversion,f_htmlcontent", "", "", t); foreach (var item in activeFile) { sara.dd.ldsw.model.tbl_app_version_html model = new sara.dd.ldsw.model.tbl_app_version_html(); string htmlName = item.FilePath + "\\" + item.FileName; htmlName = htmlName.Replace(rootpath, "").Replace("\\", "/"); string htmlContent = ""; if (item.FileExtName == ".html" || item.FileExtName == ".js" || item.FileExtName == ".css") { htmlContent = FileOperation.ReadFile(item.FilePath + "\\" + item.FileName); } //验证如果文件存在于数据库中 System.Data.DataRow[] drs = dt.Select(" f_htmlname = '" + htmlName + "'"); if (drs.Length > 0) { //比较是否相同 if (htmlContent != drs[0]["f_htmlcontent"].ToString()) { model.sys_id = int.Parse(drs[0]["sys_id"].ToString()); model.f_htmlversion = GetVersion(drs[0]["f_htmlversion"].ToString()); model.f_htmlcontent = htmlContent; model.sys_lasteditdate = System.DateTime.Now; dal.Update(model, "sys_id,f_htmlversion,f_htmlcontent,sys_lasteditdate", t); } } else { model.f_htmlname = htmlName; model.f_htmlversion = "1.0.0"; model.f_htmlcontent = htmlContent; model.sys_delflag = "0"; model.sys_creatdate = System.DateTime.Now; model.sys_lasteditdate = System.DateTime.Now; dal.Add(model, t); } } t.getTrans().commit(); resultDic["result"] = "true"; resultDic["message"] = ""; } catch (Exception ex) { if (t != null) { t.getTrans().rollback(); } resultDic["result"] = "false"; resultDic["message"] = Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace); } return(Eva.Library.Format.FormatEntityTool.FormatDicToJson(resultDic)); }
public string LibSaraPlatformOperationUIForDebugJs() { string projectName = "sara.dd.ldsw"; string errorFileName = ""; string rootPathString = @"C:\inetpub\wwwroot\sara\"; string sourcePathString = @"sara.platform.operation\"; string targetPathString = projectName + @"\sara.platform.operation\"; //删除已有文件 if (Directory.Exists(rootPathString + targetPathString)) { Directory.Delete(rootPathString + targetPathString, true); } //需要拷贝的文件 string[] copyExtNameArry = { ".html", ".css", ".js", ".asmx", ".png", ".gif" }; //需要修改参数的文件 string[] editExtNameArray = { ".html", ".js" }; //获取文件夹下的所有文件集合 List <FileInformation> list = DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(rootPathString + sourcePathString)); Eva.Library.Collection.NoRepeatingStringCollection n = new Eva.Library.Collection.NoRepeatingStringCollection(); foreach (var item in list) { n.Add(item.FileExtName); #region 是否拷贝 bool isCopy = false; if (copyExtNameArry.Contains(item.FileExtName)) { if (item.FileExtName == ".js") { if (item.FileName.Contains(".min.js")) { isCopy = false; } else { isCopy = true; } } else if (item.FileExtName == ".css") { if (item.FileName.Contains(".min.css")) { isCopy = false; } else { isCopy = true; } } else if (item.FileExtName == ".config") { if (item.FileName.Contains(".Debug.config") || item.FileName.Contains(".Release.config")) { isCopy = false; } else { isCopy = true; } } else { isCopy = true; } } else { isCopy = false; } #endregion if (isCopy == true) { #region 拷贝文件 if (!Directory.Exists(item.FilePath.Replace(rootPathString + sourcePathString, rootPathString + targetPathString))) { Directory.CreateDirectory(item.FilePath.Replace(rootPathString + sourcePathString, rootPathString + targetPathString)); } System.IO.File.Copy(item.FilePath + "\\" + item.FileName, item.FilePath.Replace(rootPathString + sourcePathString, rootPathString + targetPathString) + "\\" + item.FileName, true); #endregion #region 修改文件内容 if (editExtNameArray.Contains(item.FileExtName)) { string targetFileFullName = item.FilePath.Replace(rootPathString + sourcePathString, rootPathString + targetPathString) + "\\" + item.FileName; string filecontent = FileOperation.ReadFile(targetFileFullName); #region 项目路径 //平台operation的路径 if (filecontent.IndexOf("【sara.platform.operation.url】") > -1) { filecontent = filecontent.Replace("【sara.platform.operation.url】", "//127.0.0.1/" + projectName + "/sara.platform.operation/"); } //资源文件路径 if (filecontent.IndexOf("【sara.resource.library.url】") > -1) { //如果是dd框架,那么sara.resource.library应该是在项目外,应该去掉 //如果是ee框架,那么sara.resource.library应该是在项目内,所以应该保留 if (projectName.IndexOf(".dd.") > -1) { filecontent = filecontent.Replace("【sara.resource.library.url】", "//162.16.166.1/sara.resource.library/"); } else { filecontent = filecontent.Replace("【sara.resource.library.url】", "//127.0.0.1/" + projectName + "/sara.resource.library/"); } } //附件文件路径 if (filecontent.IndexOf("【sara.project.url】") > -1) { filecontent = filecontent.Replace("【sara.project.url】", "//127.0.0.1/" + projectName + "/"); } //附件文件路径 if (filecontent.IndexOf("【sara.project.file.url】") > -1) { if (projectName.IndexOf(".dd.") > -1) { filecontent = filecontent.Replace("【sara.project.file.url】", "//127.0.0.1/" + projectName + ".file/"); } else { filecontent = filecontent.Replace("【sara.project.file.url】", "//127.0.0.1/" + projectName + "/sara.dd.ldsw.file/"); } } //rootip if (filecontent.IndexOf("【sara.include.rootip】") > -1) { if (projectName.IndexOf(".dd.") > -1) { filecontent = filecontent.Replace("【sara.include.rootip】", "127.0.0.1"); } else { filecontent = filecontent.Replace("【sara.include.rootip】", "127.0.0.1/" + projectName); } } #endregion #region min化问题 if (item.FileExtName == ".html" && filecontent.IndexOf("ismin: true,") > -1) { filecontent = filecontent.Replace("ismin: true,", "ismin: true,"); } if (item.FileExtName == ".html") { filecontent = filecontent.Replace(".min.js\"", ".js\"").Replace(".min.min.js\"", ".js\""); filecontent = filecontent.Replace(".min.css\"", ".css\"").Replace(".min.min.css\"", ".css\""); } #endregion errorFileName += FileOperation.writeFile(targetFileFullName, filecontent); //Console.WriteLine("拷贝并编辑文件" + item.FileName); } else { //Console.WriteLine("拷贝文件" + item.FileName); } #endregion } } return(errorFileName); }
public string PublishProject() { string errorFileName = ""; string sourceRootPathString = @"C:\inetpub\wwwroot\sara\sara.dd.ldsw"; string targetRootPathString = @"C:\inetpub\wwwroot\sara.dd.ldsw.ftp"; string str = ""; //.cs.csproj.user.suo.cache string[] copyExtNameArry = { ".html", ".txt", ".dll", ".pdb", ".xml", ".asax", ".asmx", ".ashx", ".aspx", ".png", ".gif", ".jpg", ".doc", ".db", ".woff2", ".eot", ".svg", ".ttf", ".woff", ".json", ".exe", ".xap", ".WD3", ".css", ".js", ".config", ".tcs", ".tjsp", ".txml", ".taspx", ".tjs", ".thtml", ".tcss", ".txaml", ".tsvc",".tasmx", ".zip", ".p12" }; //.html,.txt,.config,.asax,.cs,.asmx, //.csproj,.user,.suo,.dll,.pdb,.xml, //.css,.js,.png,.gif,.psd, //.cache,.jpg,.doc, //.ashx,.db,.woff2,.eot, //.svg,.ttf,.woff,.json, //.exe,.xap,.aspx,.WD3 string[] editExtNameArray = { ".html", ".config", ".js" }; List <FileInformation> list = DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(sourceRootPathString)); Eva.Library.Collection.NoRepeatingStringCollection n = new Eva.Library.Collection.NoRepeatingStringCollection(); foreach (var item in list) { str += string.Format("文件目录:{0}文件名:{1}后缀:{2}", item.FilePath, item.FileName, item.FileExtName); n.Add(item.FileExtName); bool isCopy = false; if (copyExtNameArry.Contains(item.FileExtName)) { if (item.FileExtName == ".js") { if (item.FileName.Contains(".min.js")) { isCopy = true; } else { isCopy = false; } } else if (item.FileExtName == ".css") { if (item.FileName.Contains(".min.css")) { isCopy = true; } else { isCopy = false; } } else if (item.FileExtName == ".config") { if (item.FileName.Contains(".Debug.config") || item.FileName.Contains(".Release.config")) { isCopy = false; } else { isCopy = true; } } else { isCopy = true; } } else { isCopy = false; } if (isCopy == true) { if (!Directory.Exists(item.FilePath.Replace(sourceRootPathString, targetRootPathString))) { Directory.CreateDirectory(item.FilePath.Replace(sourceRootPathString, targetRootPathString)); } System.IO.File.Copy(item.FilePath + "\\" + item.FileName, item.FilePath.Replace(sourceRootPathString, targetRootPathString) + "\\" + item.FileName, true); if (editExtNameArray.Contains(item.FileExtName)) { string targetFileFullName = item.FilePath.Replace(sourceRootPathString, targetRootPathString) + "\\" + item.FileName; string filecontent = FileOperation.ReadFile(targetFileFullName); if (filecontent.IndexOf("127.0.0.1/sara.dd.ldsw") > -1) { filecontent = filecontent.Replace("127.0.0.1/sara.dd.ldsw", "www.hotworld.com.cn"); } if (item.FileExtName == ".html" && filecontent.IndexOf("ismin: true,") > -1) { filecontent = filecontent.Replace("ismin: true,", "ismin: true,"); } if (item.FileExtName == ".html") { filecontent = filecontent.Replace(".js\"", ".min.js\"").Replace(".min.min.js\"", ".min.js\""); filecontent = filecontent.Replace(".css\"", ".min.css\"").Replace(".min.min.css\"", ".min.css\""); } errorFileName += FileOperation.writeFile(targetFileFullName, filecontent) + "\r\n"; } } } return(errorFileName); }