SlideShare a Scribd company logo
1 of 5
gcrindia@gmail.com



              Working with Files
I) Computer file System
In computing, a file system (often also written as filesystem) is a method for storing
and organizing computer files and the data they contain to make it easy to find and
access them. File systems may use a data storage device such as a hard disk or CD-
ROM.

II) Working with Drives and Folders

a) Creating a Folder

Option Explicit
Dim objFSO, objFolder, strDirectory
strDirectory = "D:logs"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strDirectory)

b) Deleting a Folder

Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.DeleteFolder("E:FSO")

c) Copying Folders

Set oFSO=createobject("Scripting.Filesystemobject")
oFSO.CopyFolder "E:gcr6", "C:jvr", True

d) Checking weather the folder available or not, if not creating the folder

Option Explicit
Dim objFSO, objFolder, strDirectory
strDirectory = "D:logs"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
   msgbox strDirectory & " already created "
else
Set objFolder = objFSO.CreateFolder(strDirectory)
end if

e) Returning a collection of Disk Drives

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = oFSO.Drives
For Each oDrive in colDrives
MsgBox "Drive letter: " & oDrive.DriveLetter
Next

f) Getting available space on a Disk Drive


      G.C.Reddy, QTP Trainer, Hyderabad (9247837478)                                1
gcrindia@gmail.com


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oDrive = oFSO.GetDrive("C:")
MsgBox "Available space: " & oDrive.AvailableSpace

III) Working with Flat Files
a) Creating a Flat File
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("E:ScriptLog.txt")

b) Checking weather the File is available or not, if not creating the File

strDirectory="E:"
strFile="Scripting.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile("E:ScriptLog.txt")
End if
c) Reading Data character by character from a Flat File
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("E:gcr.txt", 1)
Do Until objFile.AtEndOfStream
  strCharacters = objFile.Read(1)
  msgbox strCharacters
Loop
d) Deleting Data From a Flat File
e) Comparing Flat Files
f) Searching Particular Strings in a Flat File
d) Reading Data line by line from a Flat File

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("E:gcr.txt", 1)
Do Until objFile.AtEndOfStream
  strCharacters = objFile.Readline
  msgbox strCharacters
Loop

e) Reading data from a flat file and using in data driven testing

Dim fso,myfile
Set fso=createobject("scripting.filesystemobject")
Set myfile= fso.opentextfile ("F:gcr.txt",1)
myfile.skipline
While myfile.atendofline <> True
x=myfile.readline
s=split (x, ",")



      G.C.Reddy, QTP Trainer, Hyderabad (9247837478)                         2
gcrindia@gmail.com

SystemUtil.Run "C:Program FilesMercury InteractiveQuickTest Professionalsamples
flightappflight4a.exe","","C:Program FilesMercury InteractiveQuickTest
Professionalsamplesflightapp","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set s(0)
Dialog("Login").WinEdit("Password:").SetSecure s(1)
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
Wend

f) Writing data to a text file

Dim Stuff, myFSO, WriteStuff, dateStamp
dateStamp = Date()
Stuff = "I am Preparing this script: " &dateStamp

Set myFSO = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = myFSO.OpenTextFile("e:gcr.txt", 8, True)
WriteStuff.WriteLine(Stuff)
WriteStuff.Close
SET WriteStuff = NOTHING
SET myFSO = NOTHING

g) Delete a text file

Set objFSO=createobject("Scripting.filesystemobject")
Set txtFilepath = objFSO.GetFile("E:gcr.txt")
 txtFilepath.Delete()



h) Checking weather the File is available or not, if available delete the File

strDirectory="E:"
strFile="gcr.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDirectory & strFile) Then
Set objFile = objFSO.Getfile(strDirectory & strFile)
objFile.delete ()
End if

i) Comparing two text files

Dim f1, f2
f1="e:gcr1.txt"
f2="e:gcr2.txt"
Public Function CompareFiles (FilePath1, FilePath2)
Dim FS, File1, File2
Set FS = CreateObject("Scripting.FileSystemObject")

If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then
CompareFiles = True
Exit Function


      G.C.Reddy, QTP Trainer, Hyderabad (9247837478)                               3
gcrindia@gmail.com

End If
Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0)

CompareFiles = False
Do While File1.AtEndOfStream = False
Str1 = File1.Read
Str2 = File2.Read

CompareFiles = StrComp(Str1, Str2, 0)

If CompareFiles <> 0 Then
CompareFiles = True
Exit Do
End If
Loop

File1.Close()
File2.Close()
End Function

Call Comparefiles(f1,f2)

If CompareFiles(f1, f2) = False Then
MsgBox "Files are identical."
Else
MsgBox "Files are different."
End If

j) Counting the number of times a word appears in a file

sFileName="E:gcr.txt"
sString="gcreddy"
Const FOR_READING = 1
Dim oFso, oTxtFile, sReadTxt, oRegEx, oMatches
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oTxtFile = oFso.OpenTextFile(sFileName, FOR_READING)
sReadTxt = oTxtFile.ReadAll
Set oRegEx = New RegExp
oRegEx.Pattern = sString
oRegEx.IgnoreCase = bIgnoreCase
oRegEx.Global = True
Set oMatches = oRegEx.Execute(sReadTxt)
MatchesFound = oMatches.Count
Set oTxtFile = Nothing : Set oFso = Nothing : Set oRegEx = Nothing
msgbox MatchesFound

IV) Working with Word Docs

a) Create a word document and enter some data & save

Dim objWD
Set objWD = CreateObject("Word.Application")


      G.C.Reddy, QTP Trainer, Hyderabad (9247837478)                        4
gcrindia@gmail.com

objWD.Documents.Add

objWD.Selection.TypeText "This is some text." & Chr(13) & "This is some more text"
objWD.ActiveDocument.SaveAs "e:gcreddy.doc"
objWD.Quit

V) Working with Excel Sheets

a) Create an excel sheet and enter a value into first cell

Dim objexcel
Set objExcel = createobject("Excel.application")
objexcel.Visible = True
objexcel.Workbooks.add
objexcel.Cells(1, 1).Value = "Testing"
objexcel.ActiveWorkbook.SaveAs("f:gcreddy1.xls")
objexcel.Quit

b) Compare two excel files

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open("E:gcr1.xls")
Set objWorkbook2= objExcel.Workbooks.Open("E:gcr2.xls")

Set objWorksheet1= objWorkbook1.Worksheets(1)

Set objWorksheet2= objWorkbook2.Worksheets(1)

  For Each cell In objWorksheet1.UsedRange
     If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
         msgbox "value is different"
     Else
         msgbox "value is same"
     End If
    Next
objWorkbook1.close
objWorkbook2.close
objExcel.quit
set objExcel=nothing




      G.C.Reddy, QTP Trainer, Hyderabad (9247837478)                                 5

More Related Content

What's hot

NDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersNDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersSimon Elliston Ball
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Realtime Database with iOS and Firebase
Realtime Database with iOS and FirebaseRealtime Database with iOS and Firebase
Realtime Database with iOS and FirebaseNSCoder Mexico
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Arian Gutierrez
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3Simon Su
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaScott Hernandez
 
The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196Mahmoud Samir Fayed
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsAlexander Rubin
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applicationsjeromevdl
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Groupkchodorow
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with GroovySten Anderson
 
The Ring programming language version 1.5.1 book - Part 27 of 180
The Ring programming language version 1.5.1 book - Part 27 of 180The Ring programming language version 1.5.1 book - Part 27 of 180
The Ring programming language version 1.5.1 book - Part 27 of 180Mahmoud Samir Fayed
 
Unit testing powershell
Unit testing powershellUnit testing powershell
Unit testing powershellMatt Wrock
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBBehrouz Bakhtiari
 

What's hot (20)

NDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersNDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developers
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Realtime Database with iOS and Firebase
Realtime Database with iOS and FirebaseRealtime Database with iOS and Firebase
Realtime Database with iOS and Firebase
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
Tricks
TricksTricks
Tricks
 
The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of Things
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applications
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
 
Sequelize
SequelizeSequelize
Sequelize
 
The Ring programming language version 1.5.1 book - Part 27 of 180
The Ring programming language version 1.5.1 book - Part 27 of 180The Ring programming language version 1.5.1 book - Part 27 of 180
The Ring programming language version 1.5.1 book - Part 27 of 180
 
Unit testing powershell
Unit testing powershellUnit testing powershell
Unit testing powershell
 
Indexing
IndexingIndexing
Indexing
 
โค้ด
โค้ดโค้ด
โค้ด
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDB
 

Similar to File System Operations

Parameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputParameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputuanna
 
Everything is composable
Everything is composableEverything is composable
Everything is composableVictor Igor
 
Basic file operations CBSE class xii ln 7
Basic file operations CBSE class xii  ln 7Basic file operations CBSE class xii  ln 7
Basic file operations CBSE class xii ln 7SATHASIVAN H
 
Coding using jscript test complete
Coding using jscript test completeCoding using jscript test complete
Coding using jscript test completeViresh Doshi
 
The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180Mahmoud Samir Fayed
 
Inventory program in mca p1
Inventory program in mca p1Inventory program in mca p1
Inventory program in mca p1rameshvvv
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnGoptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnMasashi Shibata
 
The Ring programming language version 1.10 book - Part 37 of 212
The Ring programming language version 1.10 book - Part 37 of 212The Ring programming language version 1.10 book - Part 37 of 212
The Ring programming language version 1.10 book - Part 37 of 212Mahmoud Samir Fayed
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...julien.ponge
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in pythonLifna C.S
 
The Ring programming language version 1.6 book - Part 71 of 189
The Ring programming language version 1.6 book - Part 71 of 189The Ring programming language version 1.6 book - Part 71 of 189
The Ring programming language version 1.6 book - Part 71 of 189Mahmoud Samir Fayed
 
Nosql hands on handout 04
Nosql hands on handout 04Nosql hands on handout 04
Nosql hands on handout 04Krishna Sankar
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]testduser1
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]User1test
 
Asp.net create delete directory folder in c# vb.net
Asp.net   create delete directory folder in c# vb.netAsp.net   create delete directory folder in c# vb.net
Asp.net create delete directory folder in c# vb.netrelekarsushant
 

Similar to File System Operations (20)

Excel Scripting
Excel Scripting Excel Scripting
Excel Scripting
 
Parameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputParameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple input
 
QTP
QTPQTP
QTP
 
Everything is composable
Everything is composableEverything is composable
Everything is composable
 
Basic file operations CBSE class xii ln 7
Basic file operations CBSE class xii  ln 7Basic file operations CBSE class xii  ln 7
Basic file operations CBSE class xii ln 7
 
Coding using jscript test complete
Coding using jscript test completeCoding using jscript test complete
Coding using jscript test complete
 
The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180
 
Inventory program in mca p1
Inventory program in mca p1Inventory program in mca p1
Inventory program in mca p1
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnGoptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
 
Qtp test
Qtp testQtp test
Qtp test
 
The Ring programming language version 1.10 book - Part 37 of 212
The Ring programming language version 1.10 book - Part 37 of 212The Ring programming language version 1.10 book - Part 37 of 212
The Ring programming language version 1.10 book - Part 37 of 212
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
 
Examplecode
ExamplecodeExamplecode
Examplecode
 
Python IO
Python IOPython IO
Python IO
 
The Ring programming language version 1.6 book - Part 71 of 189
The Ring programming language version 1.6 book - Part 71 of 189The Ring programming language version 1.6 book - Part 71 of 189
The Ring programming language version 1.6 book - Part 71 of 189
 
Nosql hands on handout 04
Nosql hands on handout 04Nosql hands on handout 04
Nosql hands on handout 04
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 
Asp.net create delete directory folder in c# vb.net
Asp.net   create delete directory folder in c# vb.netAsp.net   create delete directory folder in c# vb.net
Asp.net create delete directory folder in c# vb.net
 

More from G.C Reddy

Qtp training in hyderabad
Qtp training in hyderabadQtp training in hyderabad
Qtp training in hyderabadG.C Reddy
 
New features in qtp11
New features in qtp11New features in qtp11
New features in qtp11G.C Reddy
 
QTP Training
QTP TrainingQTP Training
QTP TrainingG.C Reddy
 
Software+struc+doc
Software+struc+docSoftware+struc+doc
Software+struc+docG.C Reddy
 
Qtp (advanced)
Qtp (advanced)Qtp (advanced)
Qtp (advanced)G.C Reddy
 
Qtp (basics to advanced)
Qtp (basics to advanced)Qtp (basics to advanced)
Qtp (basics to advanced)G.C Reddy
 
Qtp commands
Qtp commandsQtp commands
Qtp commandsG.C Reddy
 
Object Repository
Object RepositoryObject Repository
Object RepositoryG.C Reddy
 
Advanced Qtp
Advanced QtpAdvanced Qtp
Advanced QtpG.C Reddy
 
Advanced Qtp Book
Advanced Qtp BookAdvanced Qtp Book
Advanced Qtp BookG.C Reddy
 
QTP 10 00 Guide
QTP 10 00 GuideQTP 10 00 Guide
QTP 10 00 GuideG.C Reddy
 
Manual Testing
Manual TestingManual Testing
Manual TestingG.C Reddy
 
Web Dictionary
Web DictionaryWeb Dictionary
Web DictionaryG.C Reddy
 

More from G.C Reddy (19)

Qtp training in hyderabad
Qtp training in hyderabadQtp training in hyderabad
Qtp training in hyderabad
 
Html
HtmlHtml
Html
 
Functions
FunctionsFunctions
Functions
 
New features in qtp11
New features in qtp11New features in qtp11
New features in qtp11
 
QTP Training
QTP TrainingQTP Training
QTP Training
 
Software+struc+doc
Software+struc+docSoftware+struc+doc
Software+struc+doc
 
Qtp (advanced)
Qtp (advanced)Qtp (advanced)
Qtp (advanced)
 
Qtp (basics to advanced)
Qtp (basics to advanced)Qtp (basics to advanced)
Qtp (basics to advanced)
 
Qtp commands
Qtp commandsQtp commands
Qtp commands
 
Object Repository
Object RepositoryObject Repository
Object Repository
 
Advanced Qtp
Advanced QtpAdvanced Qtp
Advanced Qtp
 
Advanced Qtp Book
Advanced Qtp BookAdvanced Qtp Book
Advanced Qtp Book
 
QTP 10 00 Guide
QTP 10 00 GuideQTP 10 00 Guide
QTP 10 00 Guide
 
Qtp Scripts
Qtp ScriptsQtp Scripts
Qtp Scripts
 
Manual Testing
Manual TestingManual Testing
Manual Testing
 
Qtp Faq
Qtp FaqQtp Faq
Qtp Faq
 
Qtp Summary
Qtp SummaryQtp Summary
Qtp Summary
 
Qtp Scripts
Qtp ScriptsQtp Scripts
Qtp Scripts
 
Web Dictionary
Web DictionaryWeb Dictionary
Web Dictionary
 

Recently uploaded

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

File System Operations

  • 1. gcrindia@gmail.com Working with Files I) Computer file System In computing, a file system (often also written as filesystem) is a method for storing and organizing computer files and the data they contain to make it easy to find and access them. File systems may use a data storage device such as a hard disk or CD- ROM. II) Working with Drives and Folders a) Creating a Folder Option Explicit Dim objFSO, objFolder, strDirectory strDirectory = "D:logs" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.CreateFolder(strDirectory) b) Deleting a Folder Set oFSO = CreateObject("Scripting.FileSystemObject") oFSO.DeleteFolder("E:FSO") c) Copying Folders Set oFSO=createobject("Scripting.Filesystemobject") oFSO.CopyFolder "E:gcr6", "C:jvr", True d) Checking weather the folder available or not, if not creating the folder Option Explicit Dim objFSO, objFolder, strDirectory strDirectory = "D:logs" Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) msgbox strDirectory & " already created " else Set objFolder = objFSO.CreateFolder(strDirectory) end if e) Returning a collection of Disk Drives Set oFSO = CreateObject("Scripting.FileSystemObject") Set colDrives = oFSO.Drives For Each oDrive in colDrives MsgBox "Drive letter: " & oDrive.DriveLetter Next f) Getting available space on a Disk Drive G.C.Reddy, QTP Trainer, Hyderabad (9247837478) 1
  • 2. gcrindia@gmail.com Set oFSO = CreateObject("Scripting.FileSystemObject") Set oDrive = oFSO.GetDrive("C:") MsgBox "Available space: " & oDrive.AvailableSpace III) Working with Flat Files a) Creating a Flat File Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile("E:ScriptLog.txt") b) Checking weather the File is available or not, if not creating the File strDirectory="E:" strFile="Scripting.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(strDirectory & strFile) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFile = objFSO.CreateTextFile("E:ScriptLog.txt") End if c) Reading Data character by character from a Flat File Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("E:gcr.txt", 1) Do Until objFile.AtEndOfStream strCharacters = objFile.Read(1) msgbox strCharacters Loop d) Deleting Data From a Flat File e) Comparing Flat Files f) Searching Particular Strings in a Flat File d) Reading Data line by line from a Flat File Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("E:gcr.txt", 1) Do Until objFile.AtEndOfStream strCharacters = objFile.Readline msgbox strCharacters Loop e) Reading data from a flat file and using in data driven testing Dim fso,myfile Set fso=createobject("scripting.filesystemobject") Set myfile= fso.opentextfile ("F:gcr.txt",1) myfile.skipline While myfile.atendofline <> True x=myfile.readline s=split (x, ",") G.C.Reddy, QTP Trainer, Hyderabad (9247837478) 2
  • 3. gcrindia@gmail.com SystemUtil.Run "C:Program FilesMercury InteractiveQuickTest Professionalsamples flightappflight4a.exe","","C:Program FilesMercury InteractiveQuickTest Professionalsamplesflightapp","open" Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set s(0) Dialog("Login").WinEdit("Password:").SetSecure s(1) Dialog("Login").WinButton("OK").Click Window("Flight Reservation").Close Wend f) Writing data to a text file Dim Stuff, myFSO, WriteStuff, dateStamp dateStamp = Date() Stuff = "I am Preparing this script: " &dateStamp Set myFSO = CreateObject("Scripting.FileSystemObject") Set WriteStuff = myFSO.OpenTextFile("e:gcr.txt", 8, True) WriteStuff.WriteLine(Stuff) WriteStuff.Close SET WriteStuff = NOTHING SET myFSO = NOTHING g) Delete a text file Set objFSO=createobject("Scripting.filesystemobject") Set txtFilepath = objFSO.GetFile("E:gcr.txt") txtFilepath.Delete() h) Checking weather the File is available or not, if available delete the File strDirectory="E:" strFile="gcr.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(strDirectory & strFile) Then Set objFile = objFSO.Getfile(strDirectory & strFile) objFile.delete () End if i) Comparing two text files Dim f1, f2 f1="e:gcr1.txt" f2="e:gcr2.txt" Public Function CompareFiles (FilePath1, FilePath2) Dim FS, File1, File2 Set FS = CreateObject("Scripting.FileSystemObject") If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then CompareFiles = True Exit Function G.C.Reddy, QTP Trainer, Hyderabad (9247837478) 3
  • 4. gcrindia@gmail.com End If Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0) Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0) CompareFiles = False Do While File1.AtEndOfStream = False Str1 = File1.Read Str2 = File2.Read CompareFiles = StrComp(Str1, Str2, 0) If CompareFiles <> 0 Then CompareFiles = True Exit Do End If Loop File1.Close() File2.Close() End Function Call Comparefiles(f1,f2) If CompareFiles(f1, f2) = False Then MsgBox "Files are identical." Else MsgBox "Files are different." End If j) Counting the number of times a word appears in a file sFileName="E:gcr.txt" sString="gcreddy" Const FOR_READING = 1 Dim oFso, oTxtFile, sReadTxt, oRegEx, oMatches Set oFso = CreateObject("Scripting.FileSystemObject") Set oTxtFile = oFso.OpenTextFile(sFileName, FOR_READING) sReadTxt = oTxtFile.ReadAll Set oRegEx = New RegExp oRegEx.Pattern = sString oRegEx.IgnoreCase = bIgnoreCase oRegEx.Global = True Set oMatches = oRegEx.Execute(sReadTxt) MatchesFound = oMatches.Count Set oTxtFile = Nothing : Set oFso = Nothing : Set oRegEx = Nothing msgbox MatchesFound IV) Working with Word Docs a) Create a word document and enter some data & save Dim objWD Set objWD = CreateObject("Word.Application") G.C.Reddy, QTP Trainer, Hyderabad (9247837478) 4
  • 5. gcrindia@gmail.com objWD.Documents.Add objWD.Selection.TypeText "This is some text." & Chr(13) & "This is some more text" objWD.ActiveDocument.SaveAs "e:gcreddy.doc" objWD.Quit V) Working with Excel Sheets a) Create an excel sheet and enter a value into first cell Dim objexcel Set objExcel = createobject("Excel.application") objexcel.Visible = True objexcel.Workbooks.add objexcel.Cells(1, 1).Value = "Testing" objexcel.ActiveWorkbook.SaveAs("f:gcreddy1.xls") objexcel.Quit b) Compare two excel files Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True Set objWorkbook1= objExcel.Workbooks.Open("E:gcr1.xls") Set objWorkbook2= objExcel.Workbooks.Open("E:gcr2.xls") Set objWorksheet1= objWorkbook1.Worksheets(1) Set objWorksheet2= objWorkbook2.Worksheets(1) For Each cell In objWorksheet1.UsedRange If cell.Value <> objWorksheet2.Range(cell.Address).Value Then msgbox "value is different" Else msgbox "value is same" End If Next objWorkbook1.close objWorkbook2.close objExcel.quit set objExcel=nothing G.C.Reddy, QTP Trainer, Hyderabad (9247837478) 5