VBScript FileSystemObject Part 2

VBScript FileSystemObject Part-2

1) Write data Continuously in a Text file.
 

Dim objFso, objTextstream, num1, num2, Res
num1=10 : num2 =20: Res=num1 + num2
Res2=num1*num2
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C REDDY\Desktop\abc.txt", 2)
objTextstream.Write "Addition of num1, num2 is: "&Res
objTextstream.Write "Multiplication of num1, num2 is: "&Res2
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing

2) Write data Line by Line in a Text file.
 

Dim objFso, objTextstream, num1, num2, Res
num1=10 : num2 =20: Res=num1 + num2
Res2=num1*num2
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C REDDY\Desktop\abc.txt", 2)
objTextstream.WriteLine "Addition of num1, num2 is: "&Res
objTextstream.WriteLine "Multiplication of num1, num2 is: "&Res2
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing

3) Append Data to in a Text file.
 

Dim objFso, objTextstream, num1, num2, Res
num1=10 : num2 =20: Res=num1 + num2
Res2=num1*num2
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C REDDY\Desktop\abc.txt", 8)
objTextstream.WriteLine "Addition of num1, num2 is: "&Res
objTextstream.WriteLine "Multiplication of num1, num2 is: "&Res2
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
------------------------------------------------
4) Read Button Names from Login dialog box and export to a Text file
 

Dim objFso, objTextstream, oButton, Buttons, button
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C REDDY\Desktop\abc.txt", 2)

Set oButton = Description.Create
oButton("Class Name").value ="WinButton"
Set Buttons = Dialog("text:=Login").ChildObjects(oButton)
Msgbox Buttons.Count
objTextstream.WriteLine "Button Names"
objTextstream.WriteLine "-------"
For i = 0 To Buttons.Count-1 Step 1
    button= Buttons(i).GetRoProperty("text")
    objTextstream.WriteLine button
Next

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
---------------------------------------
5) Count Links in Rediff home page, read link names and export to a text file.
 

Dim objFso, objTextstream, oLink, Links
Set objFso = CreateObject("scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C REDDY\Desktop\abc.txt", 2)

Set oLink = Description.Create
oLink("micclass").value = "Link"

Set Links = Browser("Rediff.com: Online Shopping,").Page("Rediff.com: Online Shopping,").ChildObjects(oLink) @@ hightlight id_;_Browser("Rediff.com: Online Shopping,").Page("Rediff.com: Online Shopping,").Link("News")_;_script infofile_;_ZIP::ssf1.xml_;_
Msgbox Links.Count
objTextstream.WriteLine "Link Names"
objTextstream.WriteLine "----------"

For i = 0 To Links.Count-1 Step 1
    objTextstream.WriteLine i+1 & ") " & Links(i).GetRoProperty("text")
i=i+1
Next

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
--------------------------------------
6) Compare two text files by Size, by Text and by Binary values.
 

Dim objFso, File1, File2, objTextstream1, objTextstream2, myContent1, myContent2
File1 = "C:\Users\G C REDDY\Desktop\abc.txt"
file2 = "C:\Users\G C REDDY\Desktop\xyz.txt"

Set objFso = CreateObject("Scripting.FileSystemObject")

'Msgbox "File 1 Size is " & objFso.GetFile(File1).Size & " Bytes"
'Msgbox "File 2 Size is " & objFso.GetFile(File2).Size & " Bytes"

'Compare two text files by SizeIf objFso.GetFile(File1).Size = objFso.GetFile(File2).Size Then
    Msgbox "Files are Same by Size"
    Else
    Msgbox "Files are Not Same by Size"
End If

Set objTextstream1 = objFso.OpenTextFile(File1)
Set objTextstream2 = objFso.OpenTextFile(File2)

myContent1= objTextstream1.ReadAll
myContent2= objTextstream2.ReadAll

'Compare two text files by TextIf StrComp(myContent1, myContent2, 1) = 0 Then
    Msgbox "Files are same by Text"
    Else
    Msgbox "Files are Not same by Text"
End If

'Compare two text files by Binary valueIf StrComp(myContent1, myContent2) = 0 Then
    Msgbox "Files are same by Binary values"
    Else
    Msgbox "Files are Not same by Binary values"
End If
objTextstream1.Close
objTextstream2.Close

Set objTextstream1 = Nothing
Set objTextstream2 = Nothing

Set objFso = Nothing

--------------------------------------------------

0 comments:

Post a Comment