
Problem writing to a plain text file
I am writing a little playlist editor application for a project. A
playlist file is a plain text file (extension either .pls or .m3u)
with a list of file locations in it, as the example below shows:
D:\R\REM\REM - Automatic For The People - Everybody Hurts.mp3
D:\R\REM\REM - Out Of Time - Losing My Religion.mp3
D:\R\REM\REM - Out Of Time - Near Wild Heaven.mp3
In my application I can read in the file locations from the text file
into an array of strings, add file locations to the array and then
write them back to the text file.
My problem is that the data written to the file seems to be in a
format that is unsupported in all MP3 playing applications, for
example Winamp or Media Player. The problem seems to be the data
written to the file is not plain text data. If you create a playlist
file using Winamp, load it into my application and make no changes,
the resulting file output contains double the number of bytes as the
original. When I open up the original playlist file in Notepad and
compare the contents to my modified one, the text is exactly the same.
If I open up the same two files in Microsoft Word, the one modified
by my application requires some sort of encoding conversion. It
suggests Unicode as the format to convert to.
How can I write my data to a file so that it doesn't need the encoding
conversion?
Here is the section of code I have been using for writing my data
(stored in playlistContentsList as an array of strings) to the file
called Test.m3u
--------------------------
Dim fs = CreateObject("Scripting.FileSystemObject")
Dim a = fs.GetFile("C:\Playlists\Test.m3u")
Dim ts = a.OpenAsTextStream(2, -1)
Dim r As Integer
For r = 0 To playlistContentsList.getUpperBound(0)
ts.writeline(playlistContentsList(r))
Next
ts.Close()
--------------------------
Thanks in advance for your help,
Jules