您的位置:首页 > 编程语言 > VB

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: