IE下使用控件实现读取本地文件功能并显示

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>photos</title>
<style type="text/css">
    #pic img{ border:1px solid #ccc; padding:1px; margin:3px;}
</style> 
</head> 
<body>
<div id="pic">
 
</div>
<script type="text/javascript">
var tbsource = "F:\\";//本地文件夹路径
var hdfiles = "";
 
var objFSO =new ActiveXObject('Scripting.FileSystemObject');
 
if(!objFSO.FolderExists(tbsource))
 
{ 
alert("<"+tbsource+">该文件夹路径不存在,或者路径不能含文件名!"); 
objFSO = null;
//return;
 
}
var objFolder = objFSO.GetFolder(tbsource); 
var colFiles = new Enumerator(objFolder.Files); 
//var re_inf1 = /\.jpg$/; 验证文件夹文件是否jpg文件 
//var re_inf1 = /\[.](jpg|gif|bmg)$/; 
//var re_inf1 =/\.(gif|jpg|jpeg|bmp|JPG)$/;
 var re_inf1 =/\.(PNG|png)$/;
for (; !colFiles.atEnd(); colFiles.moveNext()) //读取文件夹下文件
{
    var objFile = colFiles.item();   
    if(re_inf1.test(objFile.Name.toLowerCase()))     
    {     
    hdfiles = hdfiles+"<img src='F:/"+objFile.Name+"'>";     
    }
}
 
alert(hdfiles);
document.getElementById("pic").innerHTML=hdfiles;
 
</script>
</body>
</html>


posted on 2012-11-08 15:28  YangJin  阅读(399)  评论(0编辑  收藏  举报