(一)开始
从WIN95起,WIN系统的一些基本功能被封装在符合通用对象模式COM(Common Object Mode)标准的OLE组件中,在网页上可通过JavaScript语言调用shell实现一些系统功能。用JavaScript调用shell是通过ActiveXObject来实现的,见下:
(四)Folder类(文件夹)
属性:
Application
Parent ??返回父Folder
ParentFolder 返回父Folder
Title 得到目录名
方法:
CopyHere 拷贝,不支持中文文件名,支持目录拷贝
GetDetailsOf
Items 返回FolderItems目标
MoveHere 移动,不支持中文文件名,支持目录移动
NewFolder 新建,不支持
ParseName 返回FolderItem目标
GetDetailsOf 得到子目标属性
用法:
(1)若想得到文件sdr.txt的属性,可用以下实现:
var fitem=Oh.NameSpace("e://zxd//").ParseName("sdr.txt");//先得到sdr.txt的FolderItem类目标
alert(Oh.NameSpace("c://zxd//").GetDetailsOf(fitem,0/*属性参数*/));//得到子目录或字文件的属性
属性参数:
0 Retrieves the name of the item.
1 Retrieves the size of the item.
2 Retrieves the type of the item.
3 Retrieves the date and time that the item was last modified.
4 Retrieves the attributes of the item.
-1 Retrieves the info tip information for the item.
(2)如将JavaScript.zip文件拷贝到e:/new/当前目录,可用以下实现:
var fitem=Oh.NameSpace("e://").Items().Item("JavaScript.zip");//先得到FolderItem类目标
Oh.NameSpace("e://new//").CopyHere(fitem,0x0010/*拷贝参数*/);
拷贝参数
0x0001 ???磁盘被保护?
0x0008 如果以存在目标则形成“复件 JavaScript.zip”
0x0010 如果以存在目标不提示直接覆盖
(3)其他
alert(Oh.NameSpace("c://windows//help//").Title);//得到父目录
Oh.NameSpace("e://zxd//").Items();//得到FolderItems目标,既字目录和文件集
Oh.NameSpace("e://new//").MoveHere(ob,0x0000);//移动
(五)FolderItems类(文件夹下的文件集合,包括子文件夹)
属性:Count 子项目总数
方法:Item 得到子文件,参数为文件名或索引数值
用法:
alert(Oh.NameSpace("c://zxd").Items().Count);//文件夹内文件总数,包括子文件夹
alert(Oh.NameSpace("c://zxd//").Items().Item("ts.exe"));//得到FolderItem文件目标
alert(Oh.NameSpace("c://zxd//").Items().Item(3));//得到FolderItem文件目标
(六)FolderItem类(子文件)
属性:
Application
GetFolder 如果此目标是文件夹,该属性将返回该目标的Folder类
GetLink 如果此目标是快捷方式,该属性将返回该目标的IShellLinkDual类
IsBrowsable 是否能被浏览
IsFileSystem 是否文件
IsFolder 是否文件夹
IsLink 是否快捷方式
ModifyDate 返回创建时间
Name 名称
Parent 返回父目标的FolderItem
Path 返回目标的完整路径
Size 大小
Type 类型
方法:
InvokeVerb 打开目标(运行程序)
Verbs 得到FolderItemVerbs类目标
用法:
alert(Oh.NameSpace("e://").Items().Item("一些JS技术.htm").name);//"一些JS技术.htm" 支持中文
alert(Oh.NameSpace("e://new//").Items().Item("JavaScript.zip").Path);//得到文件path "E:/new/JavaScript.zip"
alert(Oh.NameSpace("c://zxd//").Items().Item("计算器.pif").GetLink);//得到源文件
alert(Oh.NameSpace("c://zxd//").Items().Item("计算器.pif").IsFolder);//是否文件夹IsLink,IsFileSystem,IsBrowsable
alert(Oh.NameSpace("c://zxd//").Items().Item("计算器.pif").date);
alert(Oh.NameSpace("e://new//").Items().Item("JavaScript.zip").Size);//得到文件大小 72259字节,文件夹为0
alert(Oh.NameSpace("e://new//").Items().Item("JavaScript.zip").Type);//得到文件类型 "zip 文件" "文件夹"
Oh.NameSpace("e://new").Items().Item("JavaScript.zip").InvokeVerb(od);//运行