VB Code:
Public Function ReadFile(ByVal sFileName As String) As String
Dim hFile As Integer
On Error Resume Next
'Get a free file handle
hFile = FreeFile
'Open the file
Open sFileName For Input As #hFile
'read the whole content and return it
ReadFile = Input(LOF(hFile), hFile)
'Close the file
Close #hFile
End Function
You can use the above function like this:
VB Code:
Dim sText As String
sText = ReadFile("c:\thePath\theFile.txt")
Yes, if you save this text string (without changing it) you have made a copy of the origional file.
VB Code:
Public Sub SaveFile(ByVal sFileName As String, ByVal sText As String)
Dim hFile As Integer
On Error Resume Next
hFile = FreeFile
Open sFileName For Output As #hFile
Print #hFile, sText;
Close #hFile
End Sub
Here's an example:
VB Code:
Dim sTxt As String
'read the content of one (existing) file
sTxt = ReadFile("c:\FirstFile.txt")
'save this to another file
Call SaveFile("c:\SecondFile.txt", sTxt)