[Gambas-user] Problem with Exist & Open functions with filename containing spaces

Tobias Boege taboege at ...626...
Thu Mar 12 11:33:56 CET 2015


On Thu, 12 Mar 2015, John Rose wrote:
> I have coding of:
>   sPlainPath = User.Home &/ "plain out"
>   Print "PlainPath=" & sPlainPath
>   If Exist(sPlainPath) Then
>     Print sPlainPath & " exists"
>   Else
>     Print sPlainPath & " does not exist"
>   Endif
>   hPlain = Open sPlainPath For Input
>   While Not Eof(hPlain)
>     Line Input #hPlain, sLine
>     PlainTextArea.Text &= sLine & "\n"
>   Wend
>   Close #hPlain
> 
> The file 'plain out' is in my home directory. At runtime, I get popup of
> 'File or Directory does not exist'. This occurs even if I remove the 'If
> Exist(sPlainPath)...Endif' lines, which I only put in as the same error
> dialog popup also appeared in that situation. I've tried using single
> quotes to begin & end the sPlainPath value. I'm not able to amend the
> filename to exclude its inner space character as it's created by a
> command line program over which I have no control. Only solution that I
> can think of is to use Shell commands (where I presume that single
> quotes can encircle the filename) to copy/move the file to a file with
> filename not containing space characters and then open the copied file
> instead. BTW the 'plain out' file is a text file which gEdit opens OK.
> 

Gambas is able to deal with filenames containing spaces as the attached
script shows:

  $ ./path-w-spaces.gbs3
  MMain.Main.11: Path = /tmp/gambas.1000/7423/with spaces.tmp
  MMain.Main.12: Exist = True
  MMain.Main.13: Content =
  MMain.Main.16:   some string

If a *popup* pops up, this means that there is an uncaught runtime error
either in the IDE or your project. So: where is it (i.e. does the IDE
crash from the error or not?) and if it's in your project, at which line
does it occur? Does the attached script work at your side? How is it when
you create a new project and try your code above?

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list