Thanks to an answer by @RubensFarias posted in this thread I was able to fix this problem.
I have also incorporated the try...catch
method as suggested by @minitech in the comments to my origianl question, so hopefully he is satisfied that I addressed his concerns :)
Imports System.IO
Module write_text
Public Class Log_File
'*'
' Createa a log file on the users desktop and adds the 'output' text to it
'
' @param required string output The text to output to the log
'*'
Public Shared Sub write_to_file(ByVal output As String)
Dim file_name As String ' The name of the log file that is to be created
Dim file_path As String ' The full path to where the file to create and write should be saved
Dim file_exists As Boolean ' Whether or not the file already exists
Try
file_name = "MusicRenaming - " & DateTime.Today.ToString("dd-mm-yyyy") & ".txt"
file_path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\" & file_name
file_exists = File.Exists(file_path)
Using sw As New StreamWriter(File.Open(file_path, FileMode.OpenOrCreate))
sw.WriteLine(output)
End Using
Catch oError As Exception
functions.error_handler(oError)
End Try
End Sub
End Class
End Module