2024年2月10日发(作者:)
FileSystemObject详解
FSO是FileSystemObject 或
stemObject 的缩写,为 IIS 内置组件,用于操作磁盘、文件夹或文本文件。FSO 的对象、方法和属性非常的多,这里用示例的方式列出常用的,注意:《VBScript 语言参考》或《JScript 语言参考》中的:《FileSystemObject 用户指南》和《Scripting 运行时库参考》便是微软给出的 FileSystemObject 完整参考。
FSO 不能操作二进制文件,要操作二进制文件,使用:。
if fStream then
("文件的结尾!")
end if
()
set f = nothing
set fso = nothing
打开并写文件
set fso =
Object("stemObject")
set f = xtFile("C:", 2, false) '第二个参数 2 表示重写,如果是 8 表示追加
("写入内容")
ine("写入内容并换行")
lankLines(3) '写入三个空白行(相当于在文本编辑器中按三次回车)
()
set f = nothing
set fso = nothing
创建文件
set fso =
Object("stemObject")
set f = TextFile("C:", true) '第二个参数表示目标文件存在时是否覆盖
("写入内容")
ine("写入内容并换行")
lankLines(3) '写入三个空白行(相当于在文本编辑器中按三次回车)
()
set f = nothing
set fso = nothing
判断文件是否存在
set fso =
Object("stemObject")
if ists("C:") then
("目标文件存在")
else
("目标文件不存在")
end if
set fso = nothing
打开并读文件
set fso =
Object("stemObject")
set f = xtFile("C:", 1, false) '第二个参数 1 表示只读打开,第三个参数表示目标文件不存在时是否创建
(3) '将当前位置向后移三个字符
ne() '将当前位置移动到下一行的第一个字符,注意:无参数
(3) '从当前位置向后读取三个字符,并将当前位置向后移三个字符
ne() '从当前位置向后读取直到遇到换行符(不读取换行符),并将当前位置移动到下一行的第一个字符,注意:无参数
l() '从当前位置向后读取,直到文件结束,并将当前位置移动到文件的最后
if fLine then
("一行的结尾!")
end if
1
移动文件
set fso =
Object("stemObject")
call le("C:", "D:") '两个参数的文件名部分可以不同
set fso = nothing
复制文件
set fso =
Object("stemObject")
call le("C:", "D:") '两个参
FileSystemObject详解
数的文件名部分可以不同
set fso = nothing
set fs=nothing
取得某个指定的路径的父文件夹的名称
Set
fso=Object("stemObject")
p=entFolderName(h(""))
("父文件夹名称是:" & p)
set fs=nothing
删除文件
set fso =
Object("stemObject")
File("C:")
set fso = nothing
创建文件夹
set fso =
Object("stemObject")
Folder("C:test") '目标文件夹的父文件夹必须存在
set fso = nothing
取得指定路径中的最后一个成分的文件扩展名
Set fs=Object("stemObject")
(ensionName(h("")))
set fs=nothing
判断文件夹是否存在
set fso =
Object("stemObject")
if Exists("C:Windows") then
("目标文件夹存在")
else
("目标文件夹不存在")
end if
set fso = nothing
取得指定路径中的最后一个成分的文件名
Set fs=Object("stemObject")
(eName(h("")))
set fs=nothing
返回在指定的路径中文件或者文件夹的基本名称。
删除文件夹
set fso =
Object("stemObject")
Folder("C:test") '文件夹不必为空
set fso = nothing
Set
fso=Object("stemObject")
(eName("c:"))
("
")
(eName("c:windowscursors"))
("
")
(eName("c:windows"))
set fso=nothing
检测驱动器C盘是否存在
Set fso =
Object("stemObject")
xists("c:")
获取文件路径的驱动器名
Set
fso=Object("stemObject")
p=veName(h("aqa33"))
("驱动器名称是:" & p)
2


发布评论