Where is the difference between these two lines?

Check out the copy-pasta from my command window in matlab at the end.
I swapped between both lines via the arrow key. And reexecuting the same line gave the same result
I copied both lines into 2 different txt files to have notepad++ compare them, and the only difference it found was in the 'E'
So I tried both lines again, this time with a replaced E (made sure I didnt accidently add any accents or whatever).
I replaced the isfolder() with exist() and got the same weird results ( a 7 instead of logical 1).
But the result is still the same.
What is going on here?
K>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
K>> isfolder('E:\GIT\loop-test')
ans =
logical
1
K>>
K>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
K>>
K>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
K>>
K>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
K>>
K>> isfolder('E:\GIT\loop-test')
ans =
logical
1
K>> isfolder('E:\GIT\loop-test')
ans =
logical
1
K>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
>> isfolder('E:\GIT\loop-test')
ans =
logical
1
>> isfolder('E:\GIT\loop-test')
ans =
logical
1
>> isfolder('E:\GIT\loop-test')
ans =
logical
1
>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0
>> isfolder('‪E:\GIT\loop-test')
ans =
logical
0

6 Kommentare

Matt J
Matt J am 24 Jun. 2019
I copied both lines into 2 different txt files to have notepad++ compare them, and the only difference it found was in the 'E'
In what way were the E's different?
Store the two different strings in two variables, e.g:
path1 = 'E:\...'
path2 = 'E:\...' %your two different paths, any difference has been removed when you pasted them here
then show us the output of
double(path1)
double(path2)
Matt J
Matt J am 24 Jun. 2019
Check out the copy-pasta
Sounds delicious ;)
mahoromax
mahoromax am 24 Jun. 2019
Bearbeitet: mahoromax am 24 Jun. 2019
Sadly the addon for notepad++ only showed me where the text has differences, not what difference.
Okay, so this looks like quite a difference. O_o
>> double(path1)
ans =
Columns 1 through 7
8234 69 58 92 71 73 84
Columns 8 through 14
92 108 111 111 112 45 116
Columns 15 through 17
101 115 116
>> double path2
ans =
112 97 116 104 50
mahoromax
mahoromax am 24 Jun. 2019
I might also have found out, where I get those "corrupt" paths from:
I usually go to the "security" section of windows explorers properties window, to copy the object path from there.
Guillaume
Guillaume am 24 Jun. 2019
Bearbeitet: Guillaume am 24 Jun. 2019
An easier way to get the path of any object on Windows, is to press shift and right click on the object in explorer. In the extended context menu that pops up, select copy as path. This won't have any left-to-right or right-to-left control characters as well.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

mahoromax
mahoromax am 24 Jun. 2019
Bearbeitet: Rik am 24 Jun. 2019

0 Stimmen

So to summarize:
culprit was an invisible character, that windows copied when I took the filepath from the explorer properties' window
Smoother way: Shift + Rightclick and use "copy as path"
Thanks a lot @guillaume, Matt J and Rik.
And sorry for answering in a chaotic way (I first commented on the answer and then on the comments )

Weitere Antworten (1)

Matt J
Matt J am 24 Jun. 2019
Bearbeitet: Matt J am 24 Jun. 2019

0 Stimmen

My guess is that you have called the isfolder command with two different versions of the input, but with hidden characters or accents that make them look the same. Because the differences are not visible, you are unable to know which version you are executing when you use the arrow keys to scroll through the command history.

4 Kommentare

Guillaume
Guillaume am 24 Jun. 2019
Answering the question in my comment would make it immediately clear if there are different characters in each string.
mahoromax
mahoromax am 24 Jun. 2019
I can "remember" how many calls in the past which call was, and hence differentiate both
What I dont understand is why those hidden characters would not be registered in a comparison of both commands in a txt file?
I found out that if I replace the " 'E " instead of only " ' " or "E" the code works.
What kind of invisible character could that be?
Rik
Rik am 24 Jun. 2019
Bearbeitet: Rik am 24 Jun. 2019
The different character are still in the post (? for forum Unicode support). I copied the text from the post for both the true and false output.
T='E:\GIT\loop-test';
F='‪E:\GIT\loop-test';
double(T(1:3))
double(F(1:3))
The false version starts with char(8234).
Valid paths in Windows don't have a lot of limitations (link), but you're probably limited to 32-255 (excluding special characters). "The current code page" is likely something like cp1252, but apparently could support more chars. If you're certain about the code page in use on your system, you could filter all other chars away before calling isfolder.
Guillaume
Guillaume am 24 Jun. 2019
So F starts with unicode 202A, which is an invisible control character and indeed may be taken into account by the OS (nothing to do with matlab here, it's the OS that parses the path ultimately).
We can't explain why that character got there, maybe see this, but whenever you see this sort of behaviour suspect invisible characters or characters that look the same but are actually different.
Hence why I asked initially the conversion to double.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018b

Tags

Gefragt:

am 24 Jun. 2019

Bearbeitet:

Rik
am 24 Jun. 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by