Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing a particular name from a file to another file
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
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.

Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
Have you tried using XMLUtil or MSXML to read your xml file? search this forum for info on this.

Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
I got it resolved,
Thanku Pavansri Smile
Reply
#7
Solved: 11 Years, 3 Months, 3 Weeks ago
Most Welcome Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to update CSV File and need to Save same CSV File kotaramamohana 1 3,515 10-24-2015, 08:40 AM
Last Post: tigerliew
  Comapre txt file with different number of lines anushreebehura 0 1,741 06-02-2015, 06:28 PM
Last Post: anushreebehura
  How to read a text file using FSO from bottom to up order?? vallalarasu.p 0 2,505 10-13-2014, 11:14 AM
Last Post: vallalarasu.p
  How to find a file after downloading UFT_Newbie 1 2,970 09-18-2014, 08:43 PM
Last Post: UFT_Newbie
  how to create text file swayam 1 2,849 05-29-2014, 01:25 PM
Last Post: basanth27

Forum Jump:


Users browsing this thread: 1 Guest(s)