踏实,努力向上!
QTP 关于文件的操作
上一篇 /
下一篇 2009-02-08 22:10:04
/ 个人分类:QTP
创建文件
dim fso, f
set fso = CreateObject("scrīpting.FileSystemObject")
set f = fso.CreateTextFile("d:\test.txt", true) '第二个参数表示目标文件存在时是否覆盖
f.Write("写入内容")
f.WriteLine("写入内容并换行")
f.WriteBlankLines(3) '写入三个空白行(相当于在文本编辑器中按三次回车)
f.Close()
打开并读文件
dim fso, f
set fso = CreateObject("scrīpting.FileSystemObject")
set f = fso.OpenTextFile("C:\test.txt", 1, false) '第二个参数 1 表示只读打开,第三个参数表示目标文件不存在时是否创建
f.Skip(3) '将当前位置向后移三个字符
f.SkipLine() '将当前位置移动到下一行的第一个字符,注意:无参数
response.Write f.Read(3) '从当前位置向后读取三个字符,并将当前位置向后移三个字符
response.Write f.ReadLine() '从当前位置向后读取直到遇到换行符(不读取换行符),并将当前位置移动到下一行的第一个字符,注意:无参数
response.Write f.ReadAll() '从当前位置向后读取,直到文件结束,并将当前位置移动到文件的最后
if f.atEndOfLine then
response.Write("一行的结尾!")
end if
if f.atEndOfStream then
response.Write("文件的结尾!")
end if
f.Close()
set f = nothing
set fso = nothing
打开并写文件
dim fso, f
set fso = CreateObject("scrīpting.FileSystemObject")
set f = fso.OpenTextFile("C:\test.txt", 2, false) '第二个参数 2 表示重写,如果是 8 表示追加
f.Write("写入内容")
f.WriteLine("写入内容并换行")
f.WriteBlankLines(3) '写入三个空白行(相当于在文本编辑器中按三次回车)
f.Close()
set f = nothing
set fso = nothing
判断文件是否存在
dim fso
set fso = CreateObject("scrīpting.FileSystemObject")
If fso.FileExists("d:\test.txt") then
msgbox "目标文件存在"
else
msgbox "目标文件不存在"
end if
移动文件
dim fso
set fso = CreateObject("scrīpting.FileSystemObject")
call fso.MoveFile("d:\test2.txt", "e:\test111.txt") '两个参数的文件名部分可以不同. "e:\test111.txt"文件如果存在,则出错提示文件已经存在.
复制文件
dim fso
set fso = CreateObject("scrīpting.FileSystemObject")
call fso.CopyFile("d:\test2.txt", "e:\test111.txt") '两个参数的文件名部分可以不同. "e:\test111.txt"如果已经存在,也会被覆盖为新的。
删除文件
dim fso
set fso = CreateObject("scrīpting.FileSystemObject")
fso.DeleteFile("C:\test.txt")
set fso = nothing
创建文件夹
dim fso
set fso = CreateObject("scrīpting.FileSystemObject")
fso.CreateFolder("C:\test") '目标文件夹的父文件夹必须存在
set fso = nothing
判断文件夹是否存在
dim fso
set fso = CreateObject("scrīpting.FileSystemObject")
if fso.FolderExists("d:\Windows") then
msgbox"目标文件夹存在"
else
msgbox"目标文件夹不存在"
end if
set fso = nothing
删除文件夹
dim fso
set fso = CreateObject("scrīpting.FileSystemObject")
fso.DeleteFolder("C:\test") '文件夹不必为空
set fso = nothing
相关阅读:
- QTP9.5版本的delphi插件 (wuyu702, 2009-2-04)
- QTP测试修改脚本之 修改对象 (wuyu702, 2009-2-04)
- QTP无法启动 (wistaria, 2009-2-05)
- VBS中Sub与Function的区别 (胡奇, 2009-2-06)
- qtp无法录制iframe编辑器的问题 (lily4205, 2009-2-06)
- 获取WinListView的具体值,并导出表中 (lqp, 2009-2-08)
- winlistview中select的使用 (lqp, 2009-2-08)
- 写入TXT文件 (lqp, 2009-2-08)
- 拷贝的脚本无法用 (lqp, 2009-2-08)
- QTP中生成随机数 (lqp, 2009-2-08)
收藏
举报
TAG:
QTP