zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    03_线性表
    02_算法与数据结构
    01_python中内置类型的时间复杂度
    00_常见的时间复杂度
    03_docker导出和导入镜像
    09_创建mysql数据库的用户
    14_linux添加主机列表
    13_linux修改主机名
    12_centos7安装好后的网络设置
    00_使用pdb调试python代码
  • 原文地址:https://www.cnblogs.com/wml-it/p/12738117.html
Copyright © 2011-2022 走看看