Strange behaviour of File.Read

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Strange behaviour of File.Read

bill-lancaster
I must be missing something - any ideas?
Gambas3.9.2
Components, gb.form, gb,gui, gb.image

This is the code:-

Public Sub Button1_Click()
Dim s As String
  s = File.Load(User.Home &/ "Pictures/PhotoFolder.txt")
  Print s
  Print IsDir(s)
  Print IsDir("/home/bill/Pictures/Family/Visits/2000-07-29")
End

This is the output:-

"/home/bill/Pictures/Family/Visits/2000-07-29"

False
True

bb
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of File.Read

bb
On Wed, 21 Jun 2017 06:36:01 -0700 (MST)
bill-lancaster via Gambas-user <[hidden email]> wrote:

> I must be missing something - any ideas?
> Gambas3.9.2
> Components, gb.form, gb,gui, gb.image
>
> This is the code:-
>
> Public Sub Button1_Click()
> Dim s As String
>   s = File.Load(User.Home &/ "Pictures/PhotoFolder.txt")
>   Print s
>   Print IsDir(s)
>   Print IsDir("/home/bill/Pictures/Family/Visits/2000-07-29")
> End
>
> This is the output:-
>
> "/home/bill/Pictures/Family/Visits/2000-07-29"
>                                                                            <- Looks like an extra line feed
> False
> True
>
I think there is a line termination character in the PhotoFolder.txt file so
Print IsDir(s) is seeing "/home/bill/Pictures/Family/Visits/2000-07-29\n"

b
--
B Bruen <[hidden email] (sort of)>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of File.Read

Charlie
In reply to this post by bill-lancaster
bill-lancaster wrote
I must be missing something - any ideas
Try changing the line

Print IsDir(s)

to

Print IsDir(Trim(s))

It worked for me.

Check out www.gambas.one

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of File.Read

bill-lancaster
Thanks so much for the insight.

IsDir(Trim(s)) still produced False, but I tried saving the path with a Variant instead of a string and now I get True

Thanks again
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of File.Read

Jussi Lahtinen
In reply to this post by bill-lancaster
Is that the literal output?
Because if there really are quote marks, then the command is equal to:

Print IsDir("\"/home/bill/Pictures/Family/Visits/2000-07-29\"")

Which is clearly false.

However if it is not literal output, then it is impossible to say what is
read from the file to the string...



Jussi




On Wed, Jun 21, 2017 at 4:36 PM, bill-lancaster via Gambas-user <
[hidden email]> wrote:

> I must be missing something - any ideas?
> Gambas3.9.2
> Components, gb.form, gb,gui, gb.image
>
> This is the code:-
>
> Public Sub Button1_Click()
> Dim s As String
>   s = File.Load(User.Home &/ "Pictures/PhotoFolder.txt")
>   Print s
>   Print IsDir(s)
>   Print IsDir("/home/bill/Pictures/Family/Visits/2000-07-29")
> End
>
> This is the output:-
>
> "/home/bill/Pictures/Family/Visits/2000-07-29"
>
> False
> True
>
>
>
>
>
> --
> View this message in context: http://gambas.8142.n7.nabble.
> com/Strange-behaviour-of-File-Read-tp59467.html
> Sent from the gambas-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of File.Read

Jussi Lahtinen
Perhaps more clear this way, maybe your file contains line:
"/home/bill/Pictures/Family/Visits/2000-07-29" instead of
/home/bill/Pictures/Family/Visits/2000-07-29 .
So, the quote marks shouldn't be there...

Jussi

On Wed, Jun 21, 2017 at 10:47 PM, Jussi Lahtinen <[hidden email]>
wrote:

> Is that the literal output?
> Because if there really are quote marks, then the command is equal to:
>
> Print IsDir("\"/home/bill/Pictures/Family/Visits/2000-07-29\"")
>
> Which is clearly false.
>
> However if it is not literal output, then it is impossible to say what is
> read from the file to the string...
>
>
>
> Jussi
>
>
>
>
>
> On Wed, Jun 21, 2017 at 4:36 PM, bill-lancaster via Gambas-user <
> [hidden email]> wrote:
>
>> I must be missing something - any ideas?
>> Gambas3.9.2
>> Components, gb.form, gb,gui, gb.image
>>
>> This is the code:-
>>
>> Public Sub Button1_Click()
>> Dim s As String
>>   s = File.Load(User.Home &/ "Pictures/PhotoFolder.txt")
>>   Print s
>>   Print IsDir(s)
>>   Print IsDir("/home/bill/Pictures/Family/Visits/2000-07-29")
>> End
>>
>> This is the output:-
>>
>> "/home/bill/Pictures/Family/Visits/2000-07-29"
>>
>> False
>> True
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://gambas.8142.n7.nabble.c
>> om/Strange-behaviour-of-File-Read-tp59467.html
>> Sent from the gambas-user mailing list archive at Nabble.com.
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Gambas-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of File.Read

bill-lancaster
The directory string was written from a directory chooser, originally via a string variable - this is where the quotes came from.
Using a variant produces a string without quotes and presumably without \n
Thanks again
Loading...