UFT测试-vbs脚本翻译,

AtEndOfLineProperty(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)

   DoWhile theFile.AtEndOfLine <>True

      retstring = retstring&theFile.Read(1)

   Loop

   theFile.Close

   ReadFileFirstLine = retstring

   MsgBox(ReadFileFirstLine)

EndFunction

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/10240) 
   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

====== ====== ====== ====== ===== ====== ======= =====

DateLastAccessedProperty
返回指定文件或文件夹上次访问的日期和时间。只读。
对象始终是一个文件或文件夹对象

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

转载于:https://my.oschina.net/u/3098585/blog/807614

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值