I get a "permission denied" error while running the following code.
It happens on Print #to_file, one_line. Something must have changed, because it was working fine before. But I don't see anything that could've affected this. So just for clarifiction: the code creates a new file from target. This is working correctly. Then it's supposed to copy the lines from the old file (from_name) to the new file and then deletes the old file. The copying part is where it's failing.
Thanks
vb6 Code:
Public Function DeleteLines(ByVal from_name As String, ByVal to_name As String, ByVal target As String) As Long Dim strlen As Integer Dim from_file As Integer Dim to_file As Integer Dim one_line As String Dim deleted As Integer ' Open the input file. from_file = FreeFile Open from_name For Input As from_file ' Open the output file. to_file = FreeFile Open to_name For Output As to_file ' Copy the file skipping lines containing the ' target. deleted = 0 Do While Not EOF(from_file) Line Input #from_file, one_line If InStr(one_line, target) = 0 Then Print #to_file, one_line Else deleted = deleted + 1 End If Loop ' Close the files. Close from_file Close to_file Kill (from_name) Name to_name As from_name DeleteLines = deleted End Function
It happens on Print #to_file, one_line. Something must have changed, because it was working fine before. But I don't see anything that could've affected this. So just for clarifiction: the code creates a new file from target. This is working correctly. Then it's supposed to copy the lines from the old file (from_name) to the new file and then deletes the old file. The copying part is where it's failing.
Thanks