[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Some path questions
[Thread Prev] | [Thread Next]
- Subject: Re: Some path questions
- From: T Lee Davidson <t.lee.davidson@xxxxxxxxx>
- Date: Mon, 5 Aug 2024 13:30:40 -0400
- To: user@xxxxxxxxxxxxxxxxxxxxxx
On 8/5/24 09:23, Admin wrote:
Greetings, guys! Hope you all doing well. So, I have a code: -------------------------- Public Sub UpdateProgram() Dim hClient As HttpClient Dim rMatch As RegExp Dim updatequestion As Integer Dim prgURL, exeName As String prgURL = "http://whatever" exeName = "someprogram.gambas" hClient = New HttpClient As "hClient" hClient.URL = prgURL & exeName hClient.Async = False hClient.Timeout = 10 hClient.Get(, "tmp.gambas") If hClient.Status < 0 Then Return Else If Not Exist(Application.Path & "/tmp.gambas") Then message("Due to some black magic the file is not downloaded") rMatch = New RegExp(File.Load(Application.path & "/tmp.gambas"), "Version=(.*)\n") If rMatch[1].Text = Application.Version Then Try Kill "tmp.gambas" Return Else updatequestion = Message.Question("Version " & rMatch[1].Text & " is available", "Update", "Ignore") If updatequestion = 2 Or updatequestion = 3 Then Try Kill Application.Path & "/tmp.gambas" Return End If Move Application.Path & "/tmp.gambas" Kill Application.Path & "/" & exeName Chmod Application.Path & "/" & exeName To "rwxrwxrwx" Message("Version " & rMatch[1].Text & " installed. Please restart program") Quit End If End If End -----------------------------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.)
-- Lee --- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ---- --- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----
Re: Some path questions | T Lee Davidson <t.lee.davidson@xxxxxxxxx> |
Some path questions | Admin <admin@xxxxxxxxxx> |