Micro Focus QTP (UFT) Forums
Writing a particular name from a file to another file - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Writing a particular name from a file to another file (/Thread-Writing-a-particular-name-from-a-file-to-another-file)



Writing a particular name from a file to another file - zealdeep - 11-17-2009

Hi,
I need some help for reading from a text file, and writing a specific data starting with an element into another Text file

I tried with following code and the code is asfollows

Code:
Option Explicit
Dim oFSO, oTxtFile, sLine,oFilename,oFTO
Const ForWriting = 2
Const ForAppending = 8

'Dim oFSO, oTxtFile

Set oFTO = CreateObject("Scripting.FileSystemObject")
Set oTxtFile = oFTO.OpenTextFile("C:Newfolder\XXXXX.YYY_ZZZ.xml", 1)
oTxtFile.Skipline
Do Until oTxtFile.AtEndOfStream
oTxtFile.skip(70)
sLine = oTxtFile.ReadLine
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFilename = oFSO.OpenTextFile("C:\Bundle\Filename.txt",ForAppending)
oFilename.WriteBlankLines(2)
oFilename.Write (sLine)
oFilename.Close
Loop

Actually i need to open a .xml file and note all the specific name starting with Name"xyz.xml", which has a list of xml names from line 2 to end of the file,which is arounf 70 character in a line so i wondering how to capture only the name of the .xml file


RE: Writing a particular name from a file to another file - Saket - 11-17-2009

the objective is not clear, exactly what values you are trying to extract from the xml file.
you can use XMLUtil or MSXML instead of Filesystemobject for reading a xml doc.

or else if you can paste the piece of your xml structure with more explanation of what are you trying to extract, will help.


RE: Writing a particular name from a file to another file - zealdeep - 11-18-2009

the data in xml file from which i need to read data is in the below form

Code:
<manifest docCount="00005" datauri="data/ABC_XYZ.DOCS" db="ASDF" triggersuffix="POP.1289">
<details> homecsi="1212" name ="XYZ-1234.xml"/></details>
<details> homecsi="1212" name ="ABC-2345.xml"/></details>
<details> homecsi="1212" name ="ASD-3456.xml"/></details>
<details> homecsi="1212" name ="QWE-2346.xml"/></details>
</manifest>

now i will have to just read the name in each line i.e. XYZ-1234.xml, and write in another file.

I tried from the below code

Code:
Option Explicit
Dim oTxtFile, oFTO,sCharacters

'Creating an object
Set oFTO = CreateObject("Scripting.FileSystemObject")
Set oTxtFile = oFTO.OpenTextFile("D:\Documents and Settings\Desktop\sample.xml", 1)

'To skip the first line
oTxtFile.Skipline
'To read and write data from a textfile till endof stream
    Do Until oTxtFile.AtEndOfStream
    ' Skip the characters till charater 32
    oTxtFile.skip(32) ' this count of characters skipped may vary from each manifest file

   If oTxtFile.AtEndOfStream Then
    Exit Do
   End If
         sCharacters = oTxtFile.Read(12)'for reading only the .xml file name
        MsgBox sCharacters                
    oTxtFile.SkipLine
   Loop 'end of Do loop

I am looking for considering from the name element, like the xml file name (XYZ-1234.xml) should only be considered as the no. of digits in homecsi may vary from 3 to 5 digits, so could you please suggest me something where i can just consider the filename, and not the count from each line

Thanks
Deepak


RE: Writing a particular name from a file to another file - Saket - 11-18-2009

Have you tried using XMLUtil or MSXML to read your xml file? search this forum for info on this.


RE: Writing a particular name from a file to another file - pavansri - 11-19-2009

following script should solve your problem

Code:
Option Explicit
Dim oTxtFile, oFTO,sCharacters,cTextFile,i,nametofind,name

'Creating an object
Set oFTO = CreateObject("Scripting.FileSystemObject")
Set oTxtFile = oFTO.OpenTextFile("C:\test.xml", 1)

nametofind = Split ( oTxtFile.ReadAll , "name =", -1)

For i=1 To UBound(nametofind)
             name = name & vbNewLine & Mid ( nametofind(i),2,12)
Next

'disaplaying the captured names
MsgBox name

'create a txt file
Set cTextFile=oFTO.createtextfile( "C:\test.txt",true)

'writing the names captured to the text file
cTextFile.writeline name



RE: Writing a particular name from a file to another file - zealdeep - 11-21-2009

I got it resolved,
Thanku Pavansri Smile


RE: Writing a particular name from a file to another file - pavansri - 11-23-2009

Most Welcome Smile