I do not know what to tell you.
You use:
currentItem.GetSaveInfo(currentItem)
But you do not show where you save it / open it (I do not even understand that).
Also, you replace Chr(10) by a bunch of space characters and do the same with chr(13)…
and elsewhere you use EndOfLine (I nearly already stated that).
You do not share the variables DIM…
I’d better write the code by myself…
The code below seems to works fine here, but I wrote 99% of it before a nap and debug it (the 1%) after I awoke minutes ago.
My project holds:
a Listbox (LB) --> report the MP3 folder contents: Row 0: NativePath, Row 1: File Name; RowTag FolderItem MP3 item
b. a PushButton: Choose a Folder and Populates LB
c. a PushButton:Save the Listbox contents into a Text file
d. a PushButton:Read a Text file contents and set it into the Listbox
A bunch of testing debugging stuff (another PushButton to clears LB contents, a TextField to report the RowTag from the selected Row).
I will only disclose the three PushButtons Code below (what you need).
BEWARE: you have to customize the shared code to fit your needs: I just provide something I believe will work (and I hope so).
PB_Open_Folder():
Sub Action()
// Ask the user to choose the mp3 folder
// and scan its contents, Adding the NativePath / DisplayName
//
Dim MP3_FI As FolderItem // Reference of the MP3 folder
Dim aFile_FI As FolderItem // Used to check one file…
Dim Loop_Idx As Integer // Loop indice
Dim Loc_Row As Integer // Hold the value of the just added Row #
Dim Fldr_Count As Integer // How many items in the selected folder
// Ask the user to choose an MP3 folder
MP3_FI = SelectFolder()
If MP3_FI = Nil Or Not MP3_FI.Exists Then
// You may issue a MsgBox to report what happens to the user
Return
End If
// Get the number of items in the selected folder
Fldr_Count = MP3_FI.Count
// Clear the previous contents
LB.DeleteAllRows
// Scan the folder and report the files
// Nota: I do not filter the files: I display every visible item (folder or file…)
For Loop_Idx = 1 To Fldr_Count
// Get an item from the folder
aFile_FI = MP3_FI.TrueItem(Loop_Idx)
If aFile_FI.Visible And Left(aFile_FI.DisplayName,1) <> "." Then // Adapt it to your use
LB.AddRow aFile_FI.NativePath
Loc_Row = LB.LastIndex
LB.Cell(Loc_Row,1) = aFile_FI.DisplayName
LB.RowTag(Loc_Row) = aFile_FI // For Save purposes
// Clears the variable
aFile_FI = Nil
End If
If UserCancelled Then Exit
Next
End Sub
PB_Save():
Sub Action()
// Read the Listbox contents and save it into a text file
Dim MP3_FI As FolderItem // Reference of the MP3 folder
Dim aFile_FI As FolderItem // Used to check one file…
Dim Loop_Idx As Integer // Loop indice
Dim Loc_Row As Integer // Hold the value of the just added Row #
Dim LB_Count As Integer // How many items in the selected folder
// Get the number of items in the selected folder
LB_Count = LB.ListCount - 1
// Create the text file and read the LB / Save data to disk
Dim List_TOS As TextOutputStream
// Get a reference folder to save the file in
MP3_FI = GetSaveFolderItem("application/text", "MP3 Data List.txt") // File Name have to be changed !
If MP3_FI <> Nil Then
Try
List_TOS = TextOutputStream.Create(MP3_FI)
For Loop_Idx = 0 To LB_Count
// Get a Listbox entry
aFile_FI = LB.RowTag(Loop_Idx)
// Write the NativePath and DisplayName
List_TOS.WriteLine(aFile_FI.NativePath) // Write the Path
List_TOS.WriteLine(aFile_FI.DisplayName) // Write the File Name
// Toa void Infinite Loop
If UserCancelled Then Exit
Next
End Try
List_TOS.Close
End If
End Sub
PB_Read():
Sub Action()
// Read the Listbox contents and save it into a text file
Dim MP3_FI As FolderItem // Reference of the MP3 folder
Dim Loop_Idx As Integer // Loop indice
Dim Loc_Row As Integer // Hold the value of the just added Row #
Dim Fldr_Count As Integer // How many items in the selected folder
// Clears the current Listbox contents
LB.DeleteAllRows
// Create the text file and read the LB / Save data to disk
Dim List_TIS As TextInputStream
// Get a reference folder to save the file in
MP3_FI = GetOpenFolderItem("")
If MP3_FI <> Nil Then
// Get the number of items in the selected folder
Fldr_Count = MP3_FI.Count
Try
List_TIS = TextInputStream.Open(MP3_FI)
While Not List_TIS.EOF
Dim aFile_FI As FolderItem // Used to check one file…
Dim FilePath As String
Dim FileName As String
// Get the two properties of a file
FilePath = List_TIS.ReadLine
FileName = List_TIS.ReadLine
// Add a Row and Fill It !
LB.AddRow ""
Loc_Row = LB.LastIndex
LB.Cell(Loc_Row,0) = FilePath
LB.Cell(Loc_Row,1) = FileName
aFile_FI = GetFolderItem(FilePath, FolderItem.PathTypeNative)
LB.RowTag(Loc_Row) = aFile_FI
// To avoid Infinite Loop
If UserCancelled Then Exit
Wend // Next
Catch
End Try
List_TIS.Close
End If
End Sub
I hope this helps,
Emile
Message du 20/03/17 18:36
De : "ER"
A : "Nug"
Objet : Re: Endofline in File paths ?
For loading up the a listbox I loop through the folder where the mp3s
are -
(lb is a listbox passed, currentItem is FolderItem )
lb.addrow ""
lb.cell(lb.lastIndex,1) = currentItem.DisplayName
lb.Cell(lb.lastindex,2)
=currentItem.GetSaveInfo(currentItem)
--------------------------------------------------------------------------------------------------------
Saving -
dim i as Integer
for i = 0 to PlayListbox.ListCount -1
t.writeline(PlayListbox.Cell(i,1) )
pathstring = ReplaceAll(PlayListbox.Cell(i,2) ,chr(10)," ")//
need to to read in correctly, though not all were read incorrectly
pathstring= ReplaceAll(pathstring,chr(13)," ")// dito...
t.WriteLine(pathstring)
next
--------------------------------------------------------------------------------------------------------
Read -
do
txt = read.ReadLine // read in name
DisplayName.Append(txt) //add to array
txt2 = txt2+ txt + EndOfLine // for display content of playlist
in textbox
location.Append(Read.ReadLine)// path array
Loop until read.EOF
listData.Text = txt2 //textbox
read.close
Post by emile.a.schwarzAlso, saving a FolderItem as NativePath (or any other Path) can lead
into a file not found error if the original file / folder is moved
from the original location between two runs.
At last, please provide write and read code so someone may find
where an error may resides.
Emile
PS: there is a ReplaceLineEdings that is nice to use in certain
occasins, but this was needed when I tried to read a text file I do
not create.
You may check that too.
_______________________________________________
https://forum.xojo.com/
________________________________