获取磁盘空间及文件大小

<!DOCTYPE html>
<html>
    <head>
        <title>获取磁盘和文件空间的大小</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
       <form name="form1" method="post" action="">
  盘        符:	
  <input type="text" name="text1">
<input type="button" name="Button1" value="磁盘空间" onclick="DriveSize(document.form1.text1)"><br><br>
文件大小:
<input type="text" name="text2">
<input type="button" name="Button1" value="文件大小" onclick="ShowFileData(document.form1.text2.value)" >
</form>
<script language="javascript">
<!--
function DriveSize(Drivename){
	var	fso=new ActiveXObject("Scripting.FileSystemObject");
	var	s=fso.GetDrive(Drivename.value);
	if (s.IsReady){
		var str,str1,AllSize=0.0;
		str="当前驱动器的名称为:"+s.DriveLetter+"\n";
		AllSize=s.TotalSize/1024/1024/1024;
		str=str+"当前驱动器的大小为:"+parseInt(AllSize*10)/10+"\n";
		AllSize=s.FreeSpace/1024/1024/1024;
		str=str+"当前驱动器的可用空间为:"+parseInt(AllSize*10)/10;
		alert(str);
	}else
		alert("该驱动器无效。")
}
function ShowFileData(filespec){
	var fso, f, s;
    fso = new ActiveXObject("Scripting.FileSystemObject");
	f = fso.GetFile(filespec);
	s=f.type+"类型的"+f.name+"文件的大小为:"+(f.size)+"b";
	alert(s);
}

//-->
</script>

    </body>
</html>

  

posted @ 2017-12-30 20:03  勤奋的园  阅读(312)  评论(0编辑  收藏  举报