JS:读取文件类型和大小

亲测必须将代码放在记事本中,改成html格式,在用IE运行(必须)

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
		<title></title>
	</head>
	<script language="JavaScript">
		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>
		<form name="form1" method="post" action="">
			文件路径:<input type="text" name="text1" value="E:\ss.txt">
			<input type="button" name="Button1" value="文件的相关日期" onclick="ShowFileData(document.form1.text1.value)">
		</form>
	</body>
</html>

运行:

结果:

猜你喜欢

转载自blog.csdn.net/qq_42192693/article/details/82318735