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


        
///   <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);
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值