一、功能实现核心:FileSystemObject 对象 要在 javascript 中实现文件操作功能,主要就是依靠 FileSystemobject 对象
二、FileSystemObject 编程 使 用 FileSystemObject 对 象 进 行 编 程 很 简 单 , 一般 要 经 过 如 下 的 步 骤 : 创 建FileSystemObject 对象、应用相关方法、访问对象相关属性
(一)创建 FileSystemObject 对象 创建 FileSystemObject 对象的 代码只要 1 行: var fso = new ActiveXObject("Scripting
FileSystemObject"); 上述代码执行后,fso 就成为一个 FileSystemObject 对象实例
(二)应用相关方法 创建对象实例后,就可以使用对象的相关方法了
比如,使用 CreateTextFile 方法创建一个文本文件: var fso = new ActiveXObject("Scripting
FileSystemObject"); var f1 = fso
createtextfile("c:\\myjstest
txt",true"); (三)访问对象相关属性 要访问对象的相关属性,首先要建立指向对象的句柄,这就要通过 get 系列方法实现:GetDrive 负责获取驱动器信息,GetFolder 负责获取文件夹信息,GetFile 负责获取文件信息
比如,指向下面的代码后,f1 就成为指向文件 c:\test
txt 的句柄: var fso = new ActiveXObject("Scripting
FileSystemObject"); var f1 = fso
GetFile("c:\\myjstest
txt"); 然后,使用