We help IT Professionals succeed at work.

Read and write FSO

REA_ANDREW
REA_ANDREW asked
on
190 Views
Last Modified: 2010-04-23
I have a file in a folder.

In this file text is this

$$COUNTY$$

What i CAN do is copy this file a number of times into other folders.

What i do not understand is how, when i have copied the file, to open it and replace $$COUNTY$$ with a another value. Here is a snippet of my code where is the error is happening

       For i = 0 To (counties.Length - 1)  '<-------This is a long array
            System.IO.Directory.CreateDirectory(txtroot.Text & "\" & counties(i))
            'oWrite = oFile.CreateText(txtroot.Text & "\" & counties(i) & "\index.htm")
            'oWrite.WriteLine(strContents)
            File.Copy("C:\Documents and Settings\Andy\Desktop\temp\tempfiletext.php", txtroot.Text & "\" & counties(i) & "\index.php", True)'<--Here i copy the file and change the name
'*****************************************************************BELOW DOES NOT WORK
            objReader = New StreamReader(txtroot.Text & "\" & counties(i) & "\index.php")
            strContents = objReader.ReadToEnd()
            strContents = strContents.Replace("$$COUNTY$$", counties(i))
            oWrite.Write(strContents)
            oWrite.Close()
'*****************************************************************END OF WRONG CODE
            txtInput.Text = txtInput.Text & txtroot.Text & "\" & counties(i) & "\index.htm - COMPLETE" & vbCrLf
        Next i

thanks in advance

Andrew
Comment
Watch Question

Brian CroweDatabase Engineer
CERTIFIED EXPERT
Top Expert 2005

Commented:
what is happening "wrong"?  Is the value of strContents correct after the replace?

Author

Commented:
no it does not replace the value, and these two lines do not work? have you got an example of how i read the contents of a file, do the replace function and write it back in the file?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.