zoukankan      html  css  js  c++  java
  • 读取文件下的文件名称(加判定条件)


            
    /// <summary>
            
    /// 遍历路径的模板文件,并存入hashtable中
            
    /// </summary>
            
    /// <param name="directorypath">需要遍历扫描的文件夹</param>
            
    /// <param name="ht">返回的模板及配置文件</param>
            
    /// <returns>返回包含模板文件及配置文件的hashtable</returns>
            private Hashtable GetTemplatesFromPath(string directorypath)
            {
                Hashtable ht 
    = new Hashtable();
                
    //指向模板目录
                DirectoryInfo dirinfo = new DirectoryInfo(GetMapPath("templates/" + directorypath + "/"));

                
    //遍历模板目录中的文件
                foreach (FileSystemInfo file in dirinfo.GetFileSystemInfos())
                {
                    
    //将文件不为空的后缀名为.htm及不以下划线开冰的页页(即排除掉头部包含文件的模块)
                    if (file != null && (file.Extension.ToLower().Equals(".html"|| file.Extension.ToLower().Equals(".config")) && file.Name.IndexOf("_"!= 0)
                    {
                        ht[file.Name] 
    = file;
                    }
                }
                
    return ht;
            }
       /// <summary>
            
    /// 获得当前绝对路径
            
    /// </summary>
            
    /// <param name="strPath">指定的路径</param>
            
    /// <returns>绝对路径</returns>
            public static string GetMapPath(string strPath)
            {
                
    if (HttpContext.Current != null)
                {
                    
    return HttpContext.Current.Server.MapPath(strPath);
                    
    //return strPath;
                }
                
    else //非web程序引用
                {
                    strPath 
    = strPath.Replace("/""\\");
                    
    if (strPath.StartsWith("\\"))
                    {
                        strPath 
    = strPath.Substring(strPath.IndexOf('\\'1)).TrimStart('\\');
                    }
                    
    return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
                }
            }
  • 相关阅读:
    vue销毁当前组件的事件监听
    手机端下拉加载
    解决html2canvas在苹果手机上不调用问题
    html2canvas使用
    vue中三种路由传参方式
    倒计时
    判断打开的是企业微信浏览器和微信浏览器的方法
    js计算精度不准问题
    el-input 无法触发@keyup.enter 解决方法
    浏览器渲染页面的流程(参考网上有关资料整理)
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1467786.html
Copyright © 2011-2022 走看看