Discussion:
Endofline in File paths ?
ER
2017-03-20 03:49:15 UTC
Permalink
Hi,

I have mp3s in a listbox with name and the path each mp3. I then
can select which
mp3s I want to make a playlist. Then I save the data out to a text
file.(Name and path to file)
Ok so far all is good, the data is written correctly.

Now in another part I load in the playlist(s) and display each ones
content when clicked on.
Now here is where the problem was. It read the names and path
correctly for the first several
items. However it would eventually get to some where the path data
was being read in
as the name of an mp3. I couldn't figure out why it was doing this.
Everyone one before it was read in
correctly. So after a while I starting thinking about how could a
location be read in as a name.
The only way was if some how the path data had some sort of endofline
in the path
thereby creating a new line when written out.

So I tried a ReplaceAll chr(10) and chr(13) with " " and that seem to
fix the problem.

Is a thing with getsaveInfo or paths in general ?

Thanks.


Mac OS



_______________________________________________

Xojo forum:

https://forum.xojo.com/
emile.a.schwarz
2017-03-20 06:02:49 UTC
Permalink
Hi,

 

I assume you use TextOutputStream.WriteLine and TextOutputStream.ReadLine.

 

I also assume that either you store path and file name in the same line using a Chr(9) delimiter or using two  lines.

 

I assume you store and read the data in the same order.

 

At last,I assume you use a Try Catch part surrounding the Read / Write parts.


 

If all of the above is true, I cannot understand why you can reach a trouble.


 

A simple note: you may skip the file name save / read since at first, you already extract the file name from the path.


Also, 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.


 

 
Message du 20/03/17 04:50
De : "ER"
A : "Nug"
Objet : Endofline in File paths ?
Hi,
I have mp3s in a listbox with name and the path each mp3. I then
can select which
mp3s I want to make a playlist. Then I save the data out to a text
file.(Name and path to file)
Ok so far all is good, the data is written correctly.
Now in another part I load in the playlist(s) and display each ones
content when clicked on.
Now here is where the problem was. It read the names and path
correctly for the first several
items. However it would eventually get to some where the path data
was being read in
as the name of an mp3. I couldn't figure out why it was doing this.
Everyone one before it was read in
correctly. So after a while I starting thinking about how could a
location be read in as a name.
The only way was if some how the path data had some sort of endofline
in the path
thereby creating a new line when written out.
So I tried a ReplaceAll chr(10) and chr(13) with " " and that seem to
fix the problem.
Is a thing with getsaveInfo or paths in general ?
Thanks.
Mac OS
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://foru
ER
2017-03-20 17:35:16 UTC
Permalink
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.schwarz
Also, 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.
_______________________________________________

Xojo forum:

https://forum.xojo.com/
emile.a.schwarz
2017-03-21 13:41:23 UTC
Permalink
OK:

 

you use Chr(10), Chr(13) and EndOfLine.

 

Use only EndOfLine and check what happens…

 

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.schwarz
Also, 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/
_______________________________________________

Xojo forum:
Jacques Chanliau
2017-03-21 16:48:35 UTC
Permalink
I have also some problems with EndOf Line when reading a record on MySQL data base.

EndOf Line is now the end of line String <http://docs.xojo.com/index.php/String> for the platform being compiled, and if I try to read a record, I have to use « ReplaceLineEndings », to convert all EndOfLine to EndOfLine.Macintosh for example, so that I can use the text of the record.

As my application is old, created with RealBasic, I imagine that some records had EndOfLine.Macintosh in the old time, and EndOfLine.Unix now ?
I am not sure to understand how EndOfLine works now.
NOTE: Starting with 2013r1, EndOfLine returns EndOfLine.Unix <http://docs.xojo.com/index.php/EndOfLine.Unix> on all OS X apps.
Jacques.
you use Chr(10), Chr(13) and EndOfLine.
Use only EndOfLine and check what happens…
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.schwarz
Also, 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/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum.
emile.a.schwarz
2017-03-21 17:48:37 UTC
Permalink
Hi Jacques,

 

I may be wrong (I’m just awaken from a nap…), but what EndOfLine have to do in a DataBase ?

 

Also, why using EndOfLine. ?

 

 

IMHO, EndOfLine works for all platforms.

 

Also IMHO, ReplaceLineEndings have to be used with TextInputStream (?), when the text contents comes from unknow locations and can be anything but not what we expect.

 

I am trying to end an answer for ER and my mind may be… not thinking correctly :(

 

Emile

 
Message du 21/03/17 17:49
De : "Jacques Chanliau"
A : "Nug"
Objet : Re: Endofline in File paths ?
I have also some problems with EndOf Line when reading a record on MySQL data base. EndOf Line is now the end of line String for the platform being compiled, and if I try to read a record, I have to use « ReplaceLineEndings », to convert all EndOfLine to EndOfLine.Macintosh for example, so that I can use the text of the record. As my application is old, created with RealBasic, I imagine that some records had EndOfLine.Macintosh in the old time, and EndOfLine.Unix now ? I am not sure to understand how EndOfLine works now. > > NOTE: Starting with 2013r1, EndOfLine returns EndOfLine.Unix on all OS X apps. > Jacques. > Le 21 mars 2017 à 14:41, emile.a.schwarz a écrit : > > OK: > > > > you use Chr(10), Chr(13) and EndOfLine. > > > > Use only EndOfLine and check what happens… > > > > Emile > > > > > >> Message du 20/03/17 18:36 >> De : "ER" >> A : "Nug" >> Copie à : >> 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 >> >> >>> >>> >>> Also, 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. >>> >> >> _______________________________________________ >> >> Xojo forum: >> >> https://forum.xojo.com/ >> > _______________________________________________ > > Xojo forum: > > https://forum.xojo.com/ _______________________________________________ Xojo forum: https://forum.xojo.com/
_____________________________________________
Jacques Chanliau
2017-03-22 13:46:17 UTC
Permalink
Hi Emile,

My database as text fields, and in the text, usually medical reports, there are very often EndOfLines between chapters of the text.
The database can get records from various sources and operating systems.

Jacques.
Post by emile.a.schwarz
I may be wrong (I’m just awaken from a nap…), but what EndOfLine have to do in a DataBase ?
___________________________________________
emile.a.schwarz
2017-03-22 18:26:49 UTC
Permalink
Understand.

 

In that case, load the whole file (into a string ?) at once and then use ReplaceLineEndings against it. Then, you will have a string with know EndOfLine(s) Characters.

 

Emile

 
Message du 22/03/17 14:47
De : "Jacques Chanliau"
A : "Nug"
Objet : Re: Endofline in File paths ?
Hi Emile, My database as text fields, and in the text, usually medical reports, there are very often EndOfLines between chapters of the text. The database can get records from various sources and operating systems. Jacques. > Le 21 mars 2017 à 18:48, emile.a.schwarz a écrit : > > I may be wrong (I’m just awaken from a nap…), but what EndOfLine have to do in a DataBase ? _______________________________________________ Xojo forum: https://forum.xojo.com/
_______________________________________________

Xojo forum:

h

Valerio Pittavino
2017-03-21 17:50:31 UTC
Permalink
Hi,
EndOfLine is a char or more chars, it depends from OS I think.
If you can try on more platform you can write this code

Dim eof As String=EndOfLine

Dim chars() As Integer
For i as Integer=1 to eof.Len
chars.Append(asc(eof.Mid(i,1)))
Next

Break

in array chars you can see the number and code of chars which create the EndOfLine. I’m not sure but Windows uses chr(10)+chr(13)

to test it is simple, you must get some text from each OS end check all chars, you will find they

Sorry for my english

Valerio
Post by Jacques Chanliau
I have also some problems with EndOf Line when reading a record on MySQL data base.
EndOf Line is now the end of line String <http://docs.xojo.com/index.php/String> for the platform being compiled, and if I try to read a record, I have to use « ReplaceLineEndings », to convert all EndOfLine to EndOfLine.Macintosh for example, so that I can use the text of the record.
As my application is old, created with RealBasic, I imagine that some records had EndOfLine.Macintosh in the old time, and EndOfLine.Unix now ?
I am not sure to understand how EndOfLine works now.
NOTE: Starting with 2013r1, EndOfLine returns EndOfLine.Unix <http://docs.xojo.com/index.php/EndOfLine.Unix> on all OS X apps.
Jacques.
you use Chr(10), Chr(13) and EndOfLine.
Use only EndOfLine and check what happens…
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.schwarz
Also, 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/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

ht
ER
2017-03-21 18:08:59 UTC
Permalink
Yes, I added chr(10) and chr(13) part so the file paths would read in
correctly from the test file.
EndOfline is use for the textarea, so it would display the the names
under each other instead of side by side.

Before I added the replaceall chr(10) and chr(13) with a space it
would read in the names and paths
for the first 20 or so. Then for some odd reason part of the path for
one the mp3's would be read in as a name.
(there were several like this) and was also the same ones. Eventually
I came to the conclusion that
some how some sort of end of line character is or gotten in the file
path. Don't know how or why.

Anyway things seem to be working now. I'm wondering if this
is a known issue with file paths and if replacing chr(10) and chr(13)
with a space
is the best/safest way to fix it?
Post by emile.a.schwarz
you use Chr(10), Chr(13) and EndOfLine.
Use only EndOfLine and check what happens…
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.schwarz
Also, 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/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum.xojo.com/
emile.a.schwarz
2017-03-21 18:24:12 UTC
Permalink
Post by ER
I came to the conclusion that
some how some sort of end of line character is or gotten in the file
path. Don't know how or why.
On macOS Sierra (and prior versions), the Folder custom icon is saved as invisible file in thatfolder, and ends… with a return character (I forgot its value, probably Chr(13)…)

 

But since this is not a visible file nor an mp3 file, this does not comes in the process.

 

A test you may do is to rename a bunch (say 20 or more) of mp3 files in a test folder so you will be sure about their file names.

If you had found a pattern (the bug appears at the 15 file for example), add 5 files to that to be sure you will run into the bug.

 

If the bug disappears, check carefully your original files (the file names of these…).

 

It may exists a software somewhere who adds an EndOfLine character in the file names (who knows what crazy things people can do in their software ?).

 

I hope this helps,

 

Emile

 

BTW: to create the Read code, I took the Write method and modify it to be a Read method.

Pro: I know I read the properties in the correct order, etc.

Con: Triple check what you Copy / Paste to be sure you not let some Write only code lines :( … (I forgot one !).

 
Post by ER
Message du 21/03/17 19:09
De : "ER"
A : "Nug"
Objet : Re: Endofline in File paths ?
Yes, I added chr(10) and chr(13) part so the file paths would read in
correctly from the test file.
EndOfline is use for the textarea, so it would display the the names
under each other instead of side by side.
Before I added the replaceall chr(10) and chr(13) with a space it
would read in the names and paths
for the first 20 or so. Then for some odd reason part of the path for
one the mp3's would be read in as a name.
(there were several like this) and was also the same ones. Eventually
I came to the conclusion that
some how some sort of end of line character is or gotten in the file
path. Don't know how or why.
Anyway things seem to be working now. I'm wondering if this
is a known issue with file paths and if replacing chr(10) and chr(13)
with a space
is the best/safest way to fix it?
Post by emile.a.schwarz
you use Chr(10), Chr(13) and EndOfLine.
Use only EndOfLine and check what happens…
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.schwarz
Also, 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/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
______________________________
ER
2017-03-21 19:05:29 UTC
Permalink
Post by emile.a.schwarz
On macOS Sierra (and prior versions), the Folder custom icon is
saved as invisible file in thatfolder, and ends… with a return
character (I forgot its value, probably Chr(13)…)
But since this is not a visible file nor an mp3 file, this does not comes in the process.
A test you may do is to rename a bunch (say 20 or more) of mp3 files
in a test folder so you will be sure about their file names.
If you had found a pattern (the bug appears at the 15 file for
example), add 5 files to that to be sure you will run into the bug.
If the bug disappears, check carefully your original files (the file names of these…).
It may exists a software somewhere who adds an EndOfLine character
in the file names (who knows what crazy things people can do in
their software ?).
Yeah It was only with certain mp3's. No real pattern to it.

I checked a few of the mp3s where the issue was and they seemed ok.

Your code you posted is very close to what I already had, read/write,
filling listbox, etc...

It's an oddity for sure. All the mp3s are in one folder and there is
lot of them.
Never had an issue like this before.

Well things seem to be working now(replacing chr(10) and chr(13))

Thanks.


_______________________________________________

Xojo forum:

https://forum.xojo.com/
Emile Schwarz
2017-03-21 21:01:37 UTC
Permalink
Post by ER
Well things seem to be working now(replacing chr(10) and chr(13))
How can this be ?
If you store/restore the text data from the Listbox using TextOutputStream.WriteLine("the data") / TextOutputStream.ReadLine(), you are not in charge of the EndOfLine character(s)… and no error can happens.
You can make another check: move, say by 10, your mp3 files into a brand new folder and test your application against that folder. Once you fall into a trap, move back the last pack of 10 files, check, then if no error, check the names of these 10 files… / if you found nothing, rename these files and check the results.


De : ER <***@gmail.com>
À : Nug <***@lists.xojo.com>
Envoyé le : Mardi 21 mars 2017 20h06
Objet : Re: Endofline in File paths ?
Post by ER
On macOS Sierra (and prior versions), the Folder custom icon is 
saved as invisible file in thatfolder, and ends… with a return 
character (I forgot its value, probably Chr(13)…)
But since this is not a visible file nor an mp3 file, this does not 
comes in the process.
A test you may do is to rename a bunch (say 20 or more) of mp3 files 
in a test folder so you will be sure about their file names.
If you had found a pattern (the bug appears at the 15 file for 
example), add 5 files to that to be sure you will run into the bug.
If the bug disappears, check carefully your original files (the file 
names of these…).
It may exists a software somewhere who adds an EndOfLine character 
in the file names (who knows what crazy things people can do in 
their software ?).
Yeah It was only with certain mp3's.  No real pattern to it.

I checked a few of the mp3s where the issue was and they seemed ok.

Your code you posted is very close to what I already had, read/write, 
filling listbox, etc...

It's an oddity for sure. All the mp3s are in one folder and there is 
lot of them.
Never had an issue like this before.

Well things seem to be working now(replacing chr(10) and chr(13))

Thanks.


_______________________________________________

Xojo forum:

https://forum.xojo.com/


_______________________________________________

Xojo forum:

https://foru
ER
2017-03-22 04:10:42 UTC
Permalink
Post by Emile Schwarz
Post by ER
Well things seem to be working now(replacing chr(10) and chr(13))
How can this be ?
I don't know. I just know its works.
Post by Emile Schwarz
If you store/restore the text data from the Listbox using
TextOutputStream.WriteLine("the data") /
TextOutputStream.ReadLine(), you are not in charge of the EndOfLine
character(s)… and no error can happens.
You can make another check: move, say by 10, your mp3 files into a
brand new folder and test your application against that folder. Once
you fall into a trap, move back the last pack of 10 files, check,
then if no error, check the names of these 10 files… / if you found
nothing, rename these files and check the results.
This is what I just tried(also removed the chr(10) and chr(13) parts)

I took about 10 mp3 including the one where the first problem occurs,
which
happens to be the 47th mp3, and copied them over to a new folder.
Only that folder was
loaded in the listbox, saved the info to the text file. Then read back
in the text file and yep the
mp3 that was the 47th one still has the issue here. So I renamed it
many different things to make the 1st , 5th,
8th and last mp3. Reload the file in listbox, save, read back in the
textfile and same thing. I even
add more mp3s in the folder and renamed that one mp3, same results.

Now I went to the main folder and removed the 47th mp3, load up the
listbox, saved, read back in the text file, no issue
with what is now the 47th mp3. It seems to be just certain mp3s/file
paths that have the issue.

One interesting thing, in the main part of the program, there is a
listbox which gets filled the same way as the Playlist one.
This one doesn't save or read from the text file, just loops through
the folder. All the mp3s play just fine, unless of course
I put in data from a playlist that had the issues.

Quite puzzling.... but with chr(10) and chr(13) it seems to fix it.



_______________________________________________

Xojo forum:

https://forum.xojo.com/
emile.a.schwarz
2017-03-21 18:06:23 UTC
Permalink
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.schwarz
Also, 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/
________________________________
Loading...