 |
| Manual Testing |
 |
|
|
|
|
|
dim oFSO
' creating the file system object
set oFSO = CreateObject ("Scripting.FileSystemObject")
' Create a new txt file
' Parameters:
' FilePath - location of the file and its name
Function CreateFile (FilePath)
' varibale that will hold the new file object
dim NewFile
' create the new text ile
set NewFile = oFSO.CreateTextFile(FilePath, True)
set CreateFile = NewFile
End Function
' Check if a specific file exist
' Parameters:
' FilePath - location of the file and its name
Function CheckFileExists (FilePath)
' check if file exist
CheckFileExists = oFSO.FileExists(FilePath)
End Function
' Write data to file
' Parameters:
' FileRef - reference to the file
' str - data to be written to the file
Function WriteToFile (byref FileRef,str)
' write str to the text file
FileRef.WriteLine(str)
End Function
' Read line from file
' Parameters:
' FileRef - reference to the file
Function ReadLineFromFile (byref FileRef)
' read line from text file
ReadLineFromFile = FileRef.ReadLine
End Function
' Read Entire Text File Test
' Parameters:
' FileRef - reference to the file
Function ReadTextFileTest(Filepath)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, Msg
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Filepath, ForReading)
ReadTextFileTest = f.Readall()
End Function
' Closes an open file.
' Parameters:
' FileRef - reference to the file
Function CloseFile (byref FileRef)
FileRef.close
End Function
' Opens a specified file and returns an object that can be used to read from, write to, or append to the file.
' Parameters:
' FilePath - location of the file and its name
' mode options are:
' ForReading - 1
' ForWriting - 2
' ForAppending - 8
Function OpenFile (FilePath,mode)
' open the txt file and retunr the File object
set OpenFile = oFSO.OpenTextFile(FilePath, mode, True)
End Function
' Copy file.
' Parameters:
' FileRef - reference to the file
Sub FileCopy ( FilePathSource,FilePathDest)
' copy source file to destination file
oFSO.CopyFile FilePathSource, FilePathDest
End Function
' Delete a file.
' Parameters:
' FileRef - reference to the file
Sub FileDelete ( FilePath)
' copy source file to destination file
oFSO.DeleteFile ( FilePath)
End Function
' Create Folder if Not Exists.
Function ReportFolderStatus(fldr)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FolderExists(fldr)) Then
Set f = fso.CreateFolder(fldr)
End If
End Function
ReportFolderStatus("C:\Temp")
' Count Number of Lines in txt file
Function NumberOfLines(FileName)
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(FileName, ForReading)
Do Until objTextFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objTextFile.ReadLine
i = i +1
Loop
NumberOfLines = UBound(arrFileLines)
objTextFile.Close
End Function
msgbox NumberOfLines("C:\Temp\myfile.txt")
|
|
|
|
 |
| Automation Testing |
 |
|
|
|
|
|