Showing posts with label File system. Show all posts
Showing posts with label File system. Show all posts

Tuesday, November 27, 2018

Test Complete- Search data in csv or text file

public function searchdatainfilr()
strfilepath="c:\test. csv
set objfso=createobject(" scripting. filesystemobject")
set infile=objfso. opentextfile("strfilepath")
set outpath=objfso. opentextfile(strfilepath & ". tmp", 2,true)
dim irowcnt
irowcnt=0

do while not infile. atendofstream
line=inline. readline
fullfile=fullfile & line
loop

log. message fullfile
if instr(fullfile, "searctxtval") >0  then
     log. message "validation pass"
else
    log. message "validation fail"
end if
infile. close
outfile. close
objfso. deletefile(strfilepath l
objfso. movefile strfilepath & ". tmp", strfilepath

end function

Tuesday, November 20, 2018

Test Complete- Move file from source to destination

function fnMovefile(Sourcepath, destinationpath)
'path given till folder level only
' code to find csv file from particular location
set foundfiles=aqfilesystem. findfiles(sourcepath, "*.csv")
if not foundfiles is nothing then
    while foundfiles. hasnext
        set afile=foundfiles. next
        var_foundfiles=afile. name
    wend
else
     log. message "no files were found"
end if
call aqfilesystem. copyfile(soyrcepath, deatinationpath)
nowtime=aqdatetime. time()
nowtime=aqstring(nowtime, ":", "_")
nowtime=aqstring(nowtime, "pm", "_")
nowtoday=aqdatetime. today()
nowtoday=aqconvert. vartostr(nowtoday)
nowtoday=aqstring.replace(nowtoday,"/","_")
destinationfile=destinationpath & "\" & varfoundfiles
destinationfilerename=destinationpath & "\" & nowtine & "_" & nowtoday & "_" & varfoundfiles
call aqfile. rename(destinationfike, desti ationfilerename)
log. message " move file with rename successfully"
end function

Test Complete - Find value is present in excel sheet or not

function searchdatainexcel(strpath, searchcol, searchval)
path="c:abc. xls"
set searchdata=DDT. exceldriver(strpath, "sheet1", true)
do while not searchdata. EOF
   if aqconvert. vartostr(searchdata. value(searchcol)) =searchvalue then
       blnflag=true
       exit do
   else
       blnflag =false
   end if
searchdata. next
loop
if blnflag =true then
    log. message "record match"
else
   log. message "record not match"
end if
end function

Friday, October 5, 2018

Read XML file as string using Vbscript

hi folks, To read XML file as entirely string we can use below logic. Hope it will useful.

set xmldoc=createobject("MICROSOFT. XMLDOM")
xmldoc. async=false
xmldoc. load(recentxmlfilepath)
for each ochdnd in xmldoc. documentelement. childnodes
     strxmldocline=ochdnd. nodename & ":" & ochdnd. text & vbcrlf
xmldocdata= xmldocdata & strxmldocline
next
msgbox xmldocdata

cheers
Trupti

Thursday, August 2, 2018

Text file edit using UFT/QTP/VBS

Hi folks

Create test file on path with content.

Test file edit data-Trupti to Jethva
Data -Trupti

Save file c:\test.txt

Now write function as
Public function fnModifytextfile(strfilepath,strchangedata)
Const ForReading=1
Const ForWriting=2
Set objfso=createobject(“scripting.filesystemobject”)
Set myfile=objfso.opentextfile(strfilepath,forreading,true)
Set mytemp=objfso.opentextfile(strfilepath & “.tmp”, forwriting,true)
Do while not myfile.atendofstream
       Myline=myfile.readline
       If instr(myline,”Data”) then
            Orignaldata=split(myline,”-“)
            Orignaldatachange=orignaldata(1)
            Datatobechange=“ “& strchangedata
            Myline=replace(myline,orignaldatachange,datatobechange)
       Endif
       Mytemp. Writeline myline
Loop
Myfile.close
Mytemp.close
Objfso.deletefile(strfilepath )
Objfso.movefile strfilepath & “.tmp”, strfilepath
Msgbox “done”
End function
Call fnModifytextfile(“c:\test.txt”,”jethva”)