C#獲取指定目錄下指定文件的方法
1.首先,需要指定獲取的文件夾,以及獲取文件的文件名;
文件夾:strLocalPath = System.Windows.Forms.Application.StartupPath + "\\ExcelTemplate\\";
文件名:temp.xlsx
2.代碼:
ExecutionResult result = new ExecutionResult(); result.Status = true; string strLocalPath = System.Windows.Forms.Application.StartupPath + "\\ExcelTemplate\\"; if (Directory.Exists(strLocalPath)) { foreach (string GCFile in Directory.GetFiles(strLocalPath, "temp.xlsx", SearchOption.TopDirectoryOnly)) { string fileName = Path.GetFileName(GCFile); string filename = Path.GetFileName(GCFile).Replace(".xlsx", "") + DateTime.Now.ToString("_yyyyMMdd") + ".xlsx"; try { File.Copy(strLocalPath + fileName, strLocalPath + "Temp\\" + filename, true); result = GetA31DayData(strLocalPath + "Temp\\" + filename); } catch (Exception ex) { result.Status = false; result.Message = "copy file to destination file exception. Msg:" + ex.Message; result.Anything = ex.Message; if (mesLog.IsErrorEnabled) { mesLog.Error(ex.StackTrace); } } } } else { result.Status = false; result.Message = "Directory not exists!"; } return result;
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#開(kāi)源的AOP框架--KingAOP基礎(chǔ)
這篇文章主要介紹了一款C#開(kāi)源的AOP框架--KingAOP框架的基礎(chǔ)知識(shí),對(duì)于想學(xué)習(xí)AOP的小伙伴來(lái)說(shuō),非常不錯(cuò),希望大家能夠喜歡。2015-12-12C#中winform實(shí)現(xiàn)自動(dòng)觸發(fā)鼠標(biāo)、鍵盤事件的方法
這篇文章主要介紹了C#中winform實(shí)現(xiàn)自動(dòng)觸發(fā)鼠標(biāo)、鍵盤事件的方法,是C#程序設(shè)計(jì)中非常實(shí)用的功能,需要的朋友可以參考下2014-08-08C#判斷一個(gè)類是否實(shí)現(xiàn)了某個(gè)接口3種實(shí)現(xiàn)方法
這篇文章主要介紹了C#判斷一個(gè)類是否實(shí)現(xiàn)了某個(gè)接口3種實(shí)現(xiàn)方法,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-06-06C#中獲取程序路徑的幾種方法及其區(qū)別說(shuō)明
這篇文章主要介紹了C#中獲取程序路徑的幾種方法及其區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07C#巧用DateTime預(yù)設(shè)可選的日期范圍(如本年度、本季度、本月等)
這篇文章主要介紹了C#巧用DateTime預(yù)設(shè)可選的日期范圍,如本年度、本季度、本月等,感興趣的小伙伴們可以參考一下2016-04-04