[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some path questions


On 8/5/24 13:30, T Lee Davidson wrote:
On 8/5/24 09:23, Admin wrote:
[snip]
-----------------------------
My question is about Application.Path. Why do I need it? What is the default path without it then. Why is it different for different operators? I mean, why hClient is downloading a file right into the program working directory, which is nice, but then not Exist nor Kill don't see it? Where do they look by default? I mean Exist ("tmp.gambas") is false, yet the file is right there, where hClient has put it. Exist (Application.Path & "/tmp.gambas") is true, as it should, but why so complicated? Maybe I am overcomplicating things.

Dmitry


You are mixing relative paths and absolute paths. For example, 'Exist ("tmp.gambas")' uses a relative path which would be in the current working directory (CWD). Application.Path is an absolute path which is why it works whereas the relative path does not.

Whether or not a file in a relative path is found depends on the CWD which, when running the application from the IDE, is your user's HOME directory. The file is not there. It is in your project's directory. It matters from where you are launching the application.

With an empty text file named "Text1" created in the project directory (under Data), try this code (launched from different directories and using 'gbs3' and/or 'gbr3') to see the differences:
[code]
   Print "Application.Path: " & Application.Path
   Print "Application.Dir: " & Application.Dir ' CWD
   Print "Text1 exists at .Path: " & IIf(Exist(Application.Path &/ "Text1"), "True", "False")
   Print "Text1 exists at .Dir: " & IIf(Exist(Application.Dir &/ "Text1"), "True", "False")
[/code]


(BTW, Benoît, Application.Path for a project run from it's directory with 'gbs3' is missing the actual project's directory. The path ends with the project's parent directory. Using 'gbr3' to launch a compiled project behaves as expected.)

I almost forgot to mention that you do not need to concatenate path strings the way you are, ie.:
Application.Path & "/tmp.gambas"
Application.Path & "/" & exeName

You can simply use the path concatenation operator '&/' which will add the slash if it is needed and won't if it is not.
For example: Application.Path &/ "tmp.gambas", or Application.Path &/ exeName
See: https://gambaswiki.org/wiki/cat/assignop


--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


References:
Some path questionsAdmin <admin@xxxxxxxxxx>
Re: Some path questionsT Lee Davidson <t.lee.davidson@xxxxxxxxx>