Discussion:
Problem with Exist & Open functions with filename containing spaces
(too old to reply)
John Rose
2015-03-12 10:07:14 UTC
Permalink
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.
--
John
Tobias Boege
2015-03-12 10:33:56 UTC
Permalink
Post by John Rose
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
Tobias Boege
2015-03-12 10:37:28 UTC
Permalink
[...] attached script [...]
This time!
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
John Rose
2015-03-12 11:22:57 UTC
Permalink
Public Sub Main()
Dim sPath As String = Temp$("with spaces")
Dim hFile As Stream
Dim sLine As String
File.Save(sPath, "some string")
Debug "Path =";; sPath
Debug "Exist =";; Exist(sPath)
Debug "Content ="
hFile = Open sPath For Input
For Each sLine In hFile.Lines
Debug " "; sLine
Next
Close #hFile
End
I've tried that program and it didn't display anything in the Console
window. I was not able to compile the attached Test app with Debug as
when I tried to add the gb.debug component (by clicking its checkbox
which did put an x in it) using Project Properties, it did not enable
the OK button. When I closed the Project Properties window & reopened
it, the checkbox was not marked with an x. So I put in Print statements
and it did not even show their results on the Console window when I ran
the Test app. BTW I think that the 'File or Directory does not exist'
window appears because I have a 'Catch' followed by
'Message.Warning(ERROR.Text)' in the coding of the relevant Sub. Is it
possible to show the line number when the Catch 'catches'? I've also
tried putting Breakpoints in my app but that didn't help.
Tobias Boege
2015-03-12 11:38:40 UTC
Permalink
Post by John Rose
Public Sub Main()
Dim sPath As String = Temp$("with spaces")
Dim hFile As Stream
Dim sLine As String
File.Save(sPath, "some string")
Debug "Path =";; sPath
Debug "Exist =";; Exist(sPath)
Debug "Content ="
hFile = Open sPath For Input
For Each sLine In hFile.Lines
Debug " "; sLine
Next
Close #hFile
End
I've tried that program and it didn't display anything in the Console
window. I was not able to compile the attached Test app with Debug as
when I tried to add the gb.debug component (by clicking its checkbox
which did put an x in it) using Project Properties, it did not enable
the OK button. When I closed the Project Properties window & reopened
it, the checkbox was not marked with an x. So I put in Print statements
and it did not even show their results on the Console window when I ran
the Test app.
The attached file was a Gambas script. You could (and should) have run it
as-is. Your project is a GUI one where you blindly put the code in a Form's
class file. But my code had a Main() procedure which is already implemented
in the Form class. You have incorrectly overridden that implementation by
inserting my Main() procedure (which was made for a script or console
application).
Post by John Rose
BTW I think that the 'File or Directory does not exist'
window appears because I have a 'Catch' followed by
'Message.Warning(ERROR.Text)' in the coding of the relevant Sub. Is it
possible to show the line number when the Catch 'catches'? I've also
tried putting Breakpoints in my app but that didn't help.
To clarify: what shows the error? A message box or a popup? Because you said
it was a popup (which I picture as a Balloon or tooltip-like window) and now
you conjecture your Message.Warning() call may be it. But if it was a popup,
as I picture it, it cannot be caused by a Message.Warning().

You get the error line with Error.Where. You could also leave the Catch out
and let the IDE display the error by itself. The IDE is good enough at that.

Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
John Rose
2015-03-12 12:11:08 UTC
Permalink
Post by Tobias Boege
Post by John Rose
Public Sub Main()
Dim sPath As String = Temp$("with spaces")
Dim hFile As Stream
Dim sLine As String
File.Save(sPath, "some string")
Debug "Path =";; sPath
Debug "Exist =";; Exist(sPath)
Debug "Content ="
hFile = Open sPath For Input
For Each sLine In hFile.Lines
Debug " "; sLine
Next
Close #hFile
End
I've tried that program and it didn't display anything in the Console
window. I was not able to compile the attached Test app with Debug as
when I tried to add the gb.debug component (by clicking its checkbox
which did put an x in it) using Project Properties, it did not enable
the OK button. When I closed the Project Properties window & reopened
it, the checkbox was not marked with an x. So I put in Print statements
and it did not even show their results on the Console window when I ran
the Test app.
The attached file was a Gambas script. You could (and should) have run it
as-is. Your project is a GUI one where you blindly put the code in a Form's
class file. But my code had a Main() procedure which is already implemented
in the Form class. You have incorrectly overridden that implementation by
inserting my Main() procedure (which was made for a script or console
application).
Post by John Rose
BTW I think that the 'File or Directory does not exist'
window appears because I have a 'Catch' followed by
'Message.Warning(ERROR.Text)' in the coding of the relevant Sub. Is it
possible to show the line number when the Catch 'catches'? I've also
tried putting Breakpoints in my app but that didn't help.
To clarify: what shows the error? A message box or a popup? Because you said
it was a popup (which I picture as a Balloon or tooltip-like window) and now
you conjecture your Message.Warning() call may be it. But if it was a popup,
as I picture it, it cannot be caused by a Message.Warning().
You get the error line with Error.Where. You could also leave the Catch out
and let the IDE display the error by itself. The IDE is good enough at that.
Regards,
Tobi
A better name for what I called a popup is a dialog window with just an
Ok button. It is caused by the Message command, because when I comment
out the Catch & Message lines in my app it does not appear. However,
the IDE (by itself) does not display any error then. Using my previously
quoted code, the 'plain out' file does not exist (though it is present
in my home directory).

Using the code below in the attached Test app when using the IDE, when I
click the Run button, a popup appears stating 'File or Directory does
not exist at line 34' which is 'hFile = Open sPath For Input'.
Public Sub RunButton_Click()
Dim sPath As String = User.Home &/ "plain out"
Dim hFile As Stream
Dim sLine As String
Print "sPath='" & sPath & "'"
Print "*******"
Debug "Path =";; sPath
Debug "Exist =";; Exist(sPath)
Debug "Content ="
hFile = Open sPath For Input
For Each sLine In hFile.Lines
Print sLine
Debug " "; sLine
Next
Close #hFile
End


Therefore, I think that there is either a problem with using Debug->Run
or commands such as 'Opening a filename containing spaces' when using
the IDE. BTW I'm using Gambas 3.6.2 'supplied' by the Gambas Stable
Launchpad Ubuntu ppa.
Benoît Minisini
2015-03-12 12:19:03 UTC
Permalink
Post by John Rose
Post by Tobias Boege
Post by John Rose
Public Sub Main()
Dim sPath As String = Temp$("with spaces")
Dim hFile As Stream
Dim sLine As String
File.Save(sPath, "some string")
Debug "Path =";; sPath
Debug "Exist =";; Exist(sPath)
Debug "Content ="
hFile = Open sPath For Input
For Each sLine In hFile.Lines
Debug " "; sLine
Next
Close #hFile
End
I've tried that program and it didn't display anything in the Console
window. I was not able to compile the attached Test app with Debug as
when I tried to add the gb.debug component (by clicking its checkbox
which did put an x in it) using Project Properties, it did not enable
the OK button. When I closed the Project Properties window & reopened
it, the checkbox was not marked with an x. So I put in Print statements
and it did not even show their results on the Console window when I ran
the Test app.
The attached file was a Gambas script. You could (and should) have run it
as-is. Your project is a GUI one where you blindly put the code in a Form's
class file. But my code had a Main() procedure which is already implemented
in the Form class. You have incorrectly overridden that implementation by
inserting my Main() procedure (which was made for a script or console
application).
Post by John Rose
BTW I think that the 'File or Directory does not exist'
window appears because I have a 'Catch' followed by
'Message.Warning(ERROR.Text)' in the coding of the relevant Sub. Is it
possible to show the line number when the Catch 'catches'? I've also
tried putting Breakpoints in my app but that didn't help.
To clarify: what shows the error? A message box or a popup? Because you said
it was a popup (which I picture as a Balloon or tooltip-like window) and now
you conjecture your Message.Warning() call may be it. But if it was a popup,
as I picture it, it cannot be caused by a Message.Warning().
You get the error line with Error.Where. You could also leave the Catch out
and let the IDE display the error by itself. The IDE is good enough at that.
Regards,
Tobi
A better name for what I called a popup is a dialog window with just an
Ok button. It is caused by the Message command, because when I comment
out the Catch & Message lines in my app it does not appear. However,
the IDE (by itself) does not display any error then. Using my previously
quoted code, the 'plain out' file does not exist (though it is present
in my home directory).
Using the code below in the attached Test app when using the IDE, when I
click the Run button, a popup appears stating 'File or Directory does
not exist at line 34' which is 'hFile = Open sPath For Input'.
Public Sub RunButton_Click()
Dim sPath As String = User.Home &/ "plain out"
Dim hFile As Stream
Dim sLine As String
Print "sPath='" & sPath & "'"
Print "*******"
Debug "Path =";; sPath
Debug "Exist =";; Exist(sPath)
Debug "Content ="
hFile = Open sPath For Input
For Each sLine In hFile.Lines
Print sLine
Debug " "; sLine
Next
Close #hFile
End
Therefore, I think that there is either a problem with using Debug->Run
or commands such as 'Opening a filename containing spaces' when using
the IDE. BTW I'm using Gambas 3.6.2 'supplied' by the Gambas Stable
Launchpad Ubuntu ppa.
There is no problem with file names with spaces inside, or any other
character except '\x00'.

I would guess that the file on your disk is not really named
"plain[space]out"

Regards,
--
Benoît Minisini
John Rose
2015-03-13 10:58:11 UTC
Permalink
Post by Benoît Minisini
Post by John Rose
Post by Tobias Boege
Post by John Rose
Public Sub Main()
Dim sPath As String = Temp$("with spaces")
Dim hFile As Stream
Dim sLine As String
File.Save(sPath, "some string")
Debug "Path =";; sPath
Debug "Exist =";; Exist(sPath)
Debug "Content ="
hFile = Open sPath For Input
For Each sLine In hFile.Lines
Debug " "; sLine
Next
Close #hFile
End
I've tried that program and it didn't display anything in the Console
window. I was not able to compile the attached Test app with Debug as
when I tried to add the gb.debug component (by clicking its checkbox
which did put an x in it) using Project Properties, it did not enable
the OK button. When I closed the Project Properties window & reopened
it, the checkbox was not marked with an x. So I put in Print statements
and it did not even show their results on the Console window when I ran
the Test app.
The attached file was a Gambas script. You could (and should) have run it
as-is. Your project is a GUI one where you blindly put the code in a Form's
class file. But my code had a Main() procedure which is already implemented
in the Form class. You have incorrectly overridden that implementation by
inserting my Main() procedure (which was made for a script or console
application).
Post by John Rose
BTW I think that the 'File or Directory does not exist'
window appears because I have a 'Catch' followed by
'Message.Warning(ERROR.Text)' in the coding of the relevant Sub. Is it
possible to show the line number when the Catch 'catches'? I've also
tried putting Breakpoints in my app but that didn't help.
To clarify: what shows the error? A message box or a popup? Because you said
it was a popup (which I picture as a Balloon or tooltip-like window) and now
you conjecture your Message.Warning() call may be it. But if it was a popup,
as I picture it, it cannot be caused by a Message.Warning().
You get the error line with Error.Where. You could also leave the Catch out
and let the IDE display the error by itself. The IDE is good enough at that.
Regards,
Tobi
A better name for what I called a popup is a dialog window with just an
Ok button. It is caused by the Message command, because when I comment
out the Catch & Message lines in my app it does not appear. However,
the IDE (by itself) does not display any error then. Using my previously
quoted code, the 'plain out' file does not exist (though it is present
in my home directory).
Using the code below in the attached Test app when using the IDE, when I
click the Run button, a popup appears stating 'File or Directory does
not exist at line 34' which is 'hFile = Open sPath For Input'.
Public Sub RunButton_Click()
Dim sPath As String = User.Home &/ "plain out"
Dim hFile As Stream
Dim sLine As String
Print "sPath='" & sPath & "'"
Print "*******"
Debug "Path =";; sPath
Debug "Exist =";; Exist(sPath)
Debug "Content ="
hFile = Open sPath For Input
For Each sLine In hFile.Lines
Print sLine
Debug " "; sLine
Next
Close #hFile
End
Therefore, I think that there is either a problem with using Debug->Run
or commands such as 'Opening a filename containing spaces' when using
the IDE. BTW I'm using Gambas 3.6.2 'supplied' by the Gambas Stable
Launchpad Ubuntu ppa.
There is no problem with file names with spaces inside, or any other
character except '\x00'.
I would guess that the file on your disk is not really named
"plain[space]out"
Regards,
Benoit,
You were correct,. As soon as I renamed it 'plain out' (i.e. with a
space), it was OK. I presume that the command line program, that I
called with an Exec, has (what I would consider to be) a bug in it re
this file name. Unfortunately I have found no means to cintact the
program's author by email/twitter/phone.

Loading...