C#獲取指定目錄下指定文件的方法
更新時間:2022年04月14日 12:59:52 作者:農(nóng)碼一生
這篇文章介紹了C#獲取指定目錄下指定文件的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
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;以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C# 從Excel讀取數(shù)據(jù)向SQL server寫入
這篇文章主要介紹了C# 從Excel讀取數(shù)據(jù)向SQL server寫入的方法,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-03-03

