• 读取文件下的文件名称(加判定条件)



            
    /// <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);
                }
            }
  • 相关阅读:
    我的2015年ccf的解答
    VS中出现“链接器工具错误,XXX工具模块对于SAFESEH映像是不安全的”的解决方法
    记录每次运行的时刻的小程序
    c语言中strcpy与strlen函数对字符串最后的''的处理
    windows8.1的启动目录的路径
    使用feof()判断文件结束时会多输出内容的原因
    [转]android sqlite db-journal文件产生原因及说明
    安卓备份 To Do(待办事项)的数据库
    下载YouTube视频的方法
    Firefox及我使用的firefox扩展
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1467786.html
Copyright © 2020-2023  润新知