Posts: 3,927
Threads: 175
Joined: Apr 2022
Reputation:
214
I want the DefaultPathAndFile$ where my exe is.
_StartDir$ sure didn't get it, that's my QB64 exe folder
_Cwd$ works if I have been in folder for awhile but sometimes seems to be wrong when just starting cold.
So I am trying this:
Code: (Select All) Function ExePath$
Dim As Long t1, t2
t1 = _InStrRev(Command$(0), "\")
t2 = _InStrRev(Command$(0), "/")
If t1 > t2 Then ExePath$ = Left$(Command$(0), t1 - 1) Else ExePath$ = Left$(Command$(0), t2 - 1)
End Function
Look alright? I add forward slash in case of Linux, Windows doesn't care. It seems to be working for all the tests I gave trying to get out of _CWD$
b = b + ...
Posts: 2,152
Threads: 222
Joined: Apr 2022
Reputation:
102
That will work. I'm not happy _CWD$ isn't working 100%. Is it incorrect or just null. If it's a null return, you could always use a delay or...
Code: (Select All) DO
_LIMIT 10
i = i + 1
ExePath$ = _CWD$
LOOP UNTIL LEN(ExePath$) OR i > 100
IF i > 100 THEN PRINT "I BLAME STEVE!": END ELSE PRINT ExePath$
Pete
Shoot first and shoot people who ask questions, later.
Posts: 2,693
Threads: 326
Joined: Apr 2022
Reputation:
217
_CWD$ is the current working directory. Say you start in D:\QB64, then CHDIR to D:\QB64\Files... _CWD$ at this point would tell you D:\QB64\Files.
_STARTDIR$ tells you the directory that you started QB64 from. Let's say you're in Drive "C:\", and you start QB64 in "D:\QB64\qb64pe.exe". _STARTDIR$ will report "C:\" to you, as that's the directory you called QB64 from.
Neither of these commands are guaranteed to tell you where your compiled program itself is located. COMMAND$(0), is the best place to look for that information, as you've noticed.
Posts: 1,587
Threads: 59
Joined: Jul 2022
Reputation:
52
Only one 32-bit long integer variable is necessary:
Code: (Select All) Function ExePath$
Dim As Long t1
t1 = _InStrRev(Command$(0), "\")
if t1 = 0 then
t1 = _InStrRev(Command$(0), "/")
end if
ExePath$ = Left$(Command$(0), t1 - 1)
End Function
Posts: 2,152
Threads: 222
Joined: Apr 2022
Reputation:
102
From the good ol' days of "Must I optimize everything you do!" or Variable? We don't need no stinkin' variable!
Code: (Select All) PRINT ExePath$
FUNCTION ExePath$
IF _INSTRREV(COMMAND$(0), "\") THEN
ExePath$ = LEFT$(COMMAND$(0), _INSTRREV(COMMAND$(0), "\") - 1)
ELSE
ExePath$ = LEFT$(COMMAND$(0), _INSTRREV(COMMAND$(0), "/") - 1)
END IF
END FUNCTION
Just sayin'
Pete
Shoot first and shoot people who ask questions, later.
Posts: 2,152
Threads: 222
Joined: Apr 2022
Reputation:
102
12-05-2022, 12:16 AM
(This post was last modified: 12-05-2022, 01:32 AM by Pete.)
I know, I know, for fun I should have....
Code: (Select All) PRINT ExePath$
FUNCTION ExePath$
IF _INSTRREV(COMMAND$(0), "\") THEN
ExePath$ = LEFT$(COMMAND$(0), ABS(_INSTRREV(COMMAND$(0), "\")) - ABS(1))
ELSE
ExePath$ = LEFT$(COMMAND$(0), ABS(_INSTRREV(COMMAND$(0), "/")) - ABS(1))
END IF
END FUNCTION
Pete
Shoot first and shoot people who ask questions, later.
Posts: 3,927
Threads: 175
Joined: Apr 2022
Reputation:
214
Absolutely, what starts with a w and has 3 letters but ends with t
I thought it was a joke about a wit missing an i, no...
b = b + ...
Posts: 2,152
Threads: 222
Joined: Apr 2022
Reputation:
102
12-05-2022, 01:36 AM
(This post was last modified: 12-05-2022, 01:37 AM by Pete.)
Or the one about the guy who failed the one question math test: What do you get when you cut a wit in half? His answer, a half-wit. Well, he was half right... two half-wits.
Pete
Shoot first and shoot people who ask questions, later.
Posts: 2,693
Threads: 326
Joined: Apr 2022
Reputation:
217
Personally, I'd go this way:
Code: (Select All) $If WIN Then
Dim Shared As String * 1 Slash: Slash = "\"
$Else
Dim Shared As String * 1 Slash: Slash = "/"
$End If
Print ExePath
Function ExePath$
ExePath$ = Left$(Command$(0), _InStrRev(Command$(0), Slash) - 1)
End Function
Here we sort out our slash direction to begin with, and save it in a stored variable for use whenever it's needed in our program. After all, if it's needed to find ExePath, then it's going to be needed when we try and make use of that path and open a file, or anything else with it as well.
Posts: 2,152
Threads: 222
Joined: Apr 2022
Reputation:
102
12-05-2022, 03:28 AM
(This post was last modified: 12-05-2022, 03:28 AM by Pete.)
Not so fast there, Sparky. Sure, I recon Windows is the only OS that uses bsackslashes, but I'm just gettin' started on my Yosemite Vista OS with Smart ASCII Old-West technology. Then you'll be sorry when ya goes to run Steve's code, ya canrsarn galoots!
- Sam
|