UFT测试-vbs脚本翻译,
2016-12-17 00:00
465 查看
AtEndOfLine Property (FileSystemObject)
如果文件指针被立即定位在文本文件的行为标记前,返回True;否则返回False
object.AtEndOfLine
Function ReadFileFirstLine(filespec)
Const ForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
Do While theFile.AtEndOfLine <> True
retstring = retstring&theFile.Read(1)
Loop
theFile.Close
ReadFileFirstLine = retstring
MsgBox(ReadFileFirstLine)
End Function
ReadFileFirstLine("D:\testfile.txt")
====== ====== ====== ====== ===== ====== ======= =====
AtEndOfStream Property (FileSystemObject)
如果文件指针是在文本文件末,返回true;否则显示False;Read-Only
object.AtEndOfStream
Function ReadEntireFile(filespec)
Const ForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
Do While theFile.AtEndOfStream <> True
retstring = theFile.ReadLine
Loop
theFile.Close
ReadEntireFile = retstring
End Function
====== ====== ====== ====== ===== ====== ======= =====
Attributes Property
设置或返回文件或文件夹的属性。读/写或只读,根据属性。
根据文件,可以式read-write/read-only
object.Attributes [= newattributes]
object: 是文件或文件夹对象的名称
newattributes: 是指定对象的属性的新值。
Constant Value Description
Normal 0 Normal file. No attributes are set.
ReadOnly 1 Read-only file. Attribute is read/write.
Hidden 2 Hidden file. Attribute is read/write.
System 4 System file. Attribute is read/write.
Volume 8 Disk drive volume label. Attribute is read-only.
Directory 16 Folder or directory. Attribute is read-only.
Archive 32 File has changed since last backup. Attribute is read/write.
Alias 1024 Link or shortcut. Attribute is read-only.
Compressed 2048 Compressed file. Attribute is read-only.
Function ToggleArchiveBit(filespec)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
If f.attributes and 32 Then
f.attributes = f.attributes - 32
ToggleArchiveBit = "Archive bit is cleared."
Else
f.attributes = f.attributes + 32
ToggleArchiveBit = "Archive bit is set."
End If
End Function
====== ====== ====== ====== ===== ====== ======= =====
AvailableSpace Property
object.AvailableSpace
返回用户指定的驱动器或网络共享上的可使用空间量
对象始终是一个驱动器对象
Function ShowAvailableSpace(drvPath)
Dim fso, d, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(fso.GetDriveName(drvPath))
s = "Drive " & UCase(drvPath) & " - "
s = s & d.VolumeName & "<BR>"
s = s & "Available Space: " & FormatNumber(d.AvailableSpace/1024, 0)
s = s & " Kbytes"
ShowAvailableSpace = s
End Function
====== ====== ====== ====== ===== ====== ======= =====
Column Property (FileSystemObject)
只读,该属性返回一个文本文件中的当前字符位置的列号。
对象始终是一个文本对象的名称。
object.Column
Function GetColumn
Const ForReading = 1, ForWriting = 2
Dim fso, f, m
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
f.Write "Hello world!"
f.Close
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
m = f.ReadLine
GetColumn = f.Column
End Function
====== ====== ====== ====== ===== ====== ======= =====
Count Property (Script Runtime)
返回集合中的项或字典对象的数目。只读
object.Count
对象总是在适用于列表中的项目之一的名称
Function ShowKeys
Dim a, d, i, s ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
a = d.Keys ' Get the keys.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & "<BR>" ' Create return string.
Next
ShowKeys = s
End Function
====== ====== ====== ====== ===== ====== ======= =====
DateCreated Property
返回指定的文件或文件夹的日期和时间创建。只读。
object.DateCreated
对象始终是一个文件或文件夹对象。
Function ShowFileInfo(filespec)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
ShowFileInfo = "Created: " & f.DateCreated
End Function
====== ====== ====== ====== ===== ====== ======= =====
DateLastAccessed Property
返回指定文件或文件夹上次访问的日期和时间。只读。
对象始终是一个文件或文件夹对象
Function ShowFileAccessInfo(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = UCase(filespec)
s = s & "Created: " & f.DateCreated
s = s & "Last Accessed: " & f.DateLastAccessed
s = s & "Last Modified: " & f.DateLastModified
ShowFileAccessInfo = s
MsgBox ShowFileAccessInfo
End Function
ShowFileAccessInfo("D:\testfile2.txt")
====== ====== ====== ====== ===== ====== ======= =====
DateLastModified Property
返回指定文件上次修改的日期和时间或文件夹。只读。
object.DateLastModified
对象始终是一个文件或文件夹对象
Function ShowFileAccessInfo(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = UCase(filespec)
s = s & "Created: " & f.DateCreated
s = s & "Last Accessed: " & f.DateLastAccessed
s = s & "Last Modified: " & f.DateLastModified
ShowFileAccessInfo = s
End Function
如果文件指针被立即定位在文本文件的行为标记前,返回True;否则返回False
object.AtEndOfLine
Function ReadFileFirstLine(filespec)
Const ForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
Do While theFile.AtEndOfLine <> True
retstring = retstring&theFile.Read(1)
Loop
theFile.Close
ReadFileFirstLine = retstring
MsgBox(ReadFileFirstLine)
End Function
ReadFileFirstLine("D:\testfile.txt")
====== ====== ====== ====== ===== ====== ======= =====
AtEndOfStream Property (FileSystemObject)
如果文件指针是在文本文件末,返回true;否则显示False;Read-Only
object.AtEndOfStream
Function ReadEntireFile(filespec)
Const ForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
Do While theFile.AtEndOfStream <> True
retstring = theFile.ReadLine
Loop
theFile.Close
ReadEntireFile = retstring
End Function
====== ====== ====== ====== ===== ====== ======= =====
Attributes Property
设置或返回文件或文件夹的属性。读/写或只读,根据属性。
根据文件,可以式read-write/read-only
object.Attributes [= newattributes]
object: 是文件或文件夹对象的名称
newattributes: 是指定对象的属性的新值。
Constant Value Description
Normal 0 Normal file. No attributes are set.
ReadOnly 1 Read-only file. Attribute is read/write.
Hidden 2 Hidden file. Attribute is read/write.
System 4 System file. Attribute is read/write.
Volume 8 Disk drive volume label. Attribute is read-only.
Directory 16 Folder or directory. Attribute is read-only.
Archive 32 File has changed since last backup. Attribute is read/write.
Alias 1024 Link or shortcut. Attribute is read-only.
Compressed 2048 Compressed file. Attribute is read-only.
Function ToggleArchiveBit(filespec)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
If f.attributes and 32 Then
f.attributes = f.attributes - 32
ToggleArchiveBit = "Archive bit is cleared."
Else
f.attributes = f.attributes + 32
ToggleArchiveBit = "Archive bit is set."
End If
End Function
====== ====== ====== ====== ===== ====== ======= =====
AvailableSpace Property
object.AvailableSpace
返回用户指定的驱动器或网络共享上的可使用空间量
对象始终是一个驱动器对象
Function ShowAvailableSpace(drvPath)
Dim fso, d, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(fso.GetDriveName(drvPath))
s = "Drive " & UCase(drvPath) & " - "
s = s & d.VolumeName & "<BR>"
s = s & "Available Space: " & FormatNumber(d.AvailableSpace/1024, 0)
s = s & " Kbytes"
ShowAvailableSpace = s
End Function
====== ====== ====== ====== ===== ====== ======= =====
Column Property (FileSystemObject)
只读,该属性返回一个文本文件中的当前字符位置的列号。
对象始终是一个文本对象的名称。
object.Column
Function GetColumn
Const ForReading = 1, ForWriting = 2
Dim fso, f, m
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
f.Write "Hello world!"
f.Close
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
m = f.ReadLine
GetColumn = f.Column
End Function
====== ====== ====== ====== ===== ====== ======= =====
Count Property (Script Runtime)
返回集合中的项或字典对象的数目。只读
object.Count
对象总是在适用于列表中的项目之一的名称
Function ShowKeys
Dim a, d, i, s ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
a = d.Keys ' Get the keys.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & "<BR>" ' Create return string.
Next
ShowKeys = s
End Function
====== ====== ====== ====== ===== ====== ======= =====
DateCreated Property
返回指定的文件或文件夹的日期和时间创建。只读。
object.DateCreated
对象始终是一个文件或文件夹对象。
Function ShowFileInfo(filespec)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
ShowFileInfo = "Created: " & f.DateCreated
End Function
====== ====== ====== ====== ===== ====== ======= =====
DateLastAccessed Property
返回指定文件或文件夹上次访问的日期和时间。只读。
对象始终是一个文件或文件夹对象
Function ShowFileAccessInfo(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = UCase(filespec)
s = s & "Created: " & f.DateCreated
s = s & "Last Accessed: " & f.DateLastAccessed
s = s & "Last Modified: " & f.DateLastModified
ShowFileAccessInfo = s
MsgBox ShowFileAccessInfo
End Function
ShowFileAccessInfo("D:\testfile2.txt")
====== ====== ====== ====== ===== ====== ======= =====
DateLastModified Property
返回指定文件上次修改的日期和时间或文件夹。只读。
object.DateLastModified
对象始终是一个文件或文件夹对象
Function ShowFileAccessInfo(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = UCase(filespec)
s = s & "Created: " & f.DateCreated
s = s & "Last Accessed: " & f.DateLastAccessed
s = s & "Last Modified: " & f.DateLastModified
ShowFileAccessInfo = s
End Function
相关文章推荐
- 测试脚本自动运行的VBS 脚本
- 标准Windows控件的常规测试方法及VBS脚本代码
- (翻译)开发自动化测试脚本的技巧和心得
- vbs脚本编写的UFT 11.5重新使用30天的程序
- 【学习随笔】由UFT脚本语言对VBS中Sub与Function简单区别
- 一个测试用的VBS脚本样例
- 基于QTP的自动化测试留下一份向数据库自动导入测试数据的VBS脚本
- UFT工具 飞机订票系统订单 价格测试脚本
- (翻译)开发自动化测试脚本的技巧和心得
- 【QTP专题-优化】VBS脚本启动QTP并运行测试
- 视频编码基准测试挑战Movie Metric Benchmark Challenge (部分翻译)
- 如何在软件频繁改变时测试?〔翻译〕
- Adsutil.vbs 在脚本攻击中的妙用
- (翻译)选择测试自动化框架
- 飘浮广告显示脚本类(VBS,JS双版)
- 如何在PB脚本当中获取存储过程的返回值(翻译)
- 利用WMI获取和更新网络设置(VBS脚本)
- 刷QQ群的VBS脚本
- (翻译)测试小技巧集锦之二文档编写
- vbs脚本加启动项提升webshell的管理权限