hi
i want to open a file and save all of it to a variable and then to write it to a new file.
how can i do it?
Printable View
hi
i want to open a file and save all of it to a variable and then to write it to a new file.
how can i do it?
Code:Function OpenFile(Filename As String) As String
On Error Resume Next
Open Filename For Input As #1
OpenFile = Input(LOF(1), 1)
Close #1
End Function
Private Sub SaveFile(Filename As String, Text As String)
On Error Resume Next
Open Filename For Output As #1
Print #1, Text
Close #1
End Sub
Ok, i hope i beat megatron to this... ;) Here goes!
The following code shows how to read the contents of a file into a string (change to variant if ya want), then place them into a new file. If you just simply want to copy the file, then use filecopy:
Other wise, use the following code.Code:FileCopy "C:\Test.txt", "C:\NewFile.txt"
Hope this helps...Code:Dim strData as string
'Get Data
Open "C:\Test.txt" for binary as #1
strData = Space(LOF(1))
get #1, , strData
Close #1
'Put the data into a new file
Open "C:\MyNewFile.txt" For binary as #1
Put #1, strData
Close #1
Laterz
REM