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);
                }
            }
  • 相关阅读:
    解决无线打印机休眠后掉线无法进行局域网打印的问题
    快速为某个目录的verilog文件生成filelist
    使用Visual Studio的Spy++查找弹窗广告进程
    【转载】verilog语法之generate语句的基本认识
    补码(为什么按位取反再加一):告诉你一个其实很简单的问题
    【转载】EDID的简介和解析
    win32diskimager 谨慎使用
    UXE的一些使用归纳
    如何在win8或win10系统里添加inf驱动程序
    STM32 USB HID
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1467786.html
Copyright © 2011-2022 走看看