这篇文章介绍了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;以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持得得之家。
				 沃梦达教程
				
			本文标题为:C#获取指定目录下指定文件的方法
 
				
         
 
            
        基础教程推荐
             猜你喜欢
        
	     - c#中利用Tu Share获取股票交易信息 2023-03-03
- C# Winform实现石头剪刀布游戏 2023-01-11
- c#读取XML多级子节点 2022-11-05
- C#通过GET/POST方式发送Http请求 2023-04-28
- Unity shader实现多光源漫反射以及阴影 2023-03-04
- 使用c#从分隔文本文件中插入SQL Server表中的批量数据 2023-11-24
- C#中类与接口的区别讲解 2023-06-04
- C#集合查询Linq在项目中使用详解 2023-06-09
- C# – NetUseAdd来自Windows Server 2008和IIS7上的NetApi32.dll 2023-09-20
- 京东联盟C#接口测试示例分享 2022-12-02
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				