Author Topic: _STARTDIR$ weirdness  (Read 2087 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
_STARTDIR$ weirdness
« on: June 19, 2020, 02:18:22 pm »
Is it an expected behavior of _STARTDIR$ to report the directory of the shortcut to the program rather than the directory that the EXE is starting in? I've had errors in some of my programs because it was using the desktop as the _STARTDIR$ since I used a shortcut. I've been using this to bypass that for now:
Code: QB64: [Select]
  1. $IF STDIR = UNDEFINED THEN
  2.     $LET STDIR = TRUE
  3.     FUNCTION StartDir$
  4.         DIM startupDir AS STRING
  5.         startupDir = COMMAND$(0)
  6.         startupDir = LEFT$(startupDir, _INSTRREV(startupDir, "\"))
  7.         StartDir = startupDir
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: _STARTDIR$ weirdness
« Reply #1 on: June 19, 2020, 02:34:36 pm »
Do you need meta commands to find the Source Folder for exe?

I don't think I have. Maybe Windows shortcut didn't goto the exe?

Update: Dang, I am sure there is command for exe path or folder, maybe it is a meta, I can't find it or recall it.

Dah!"https://www.qb64.org/wiki/STARTDIR$" copy/paste  OK time for lunch :P
« Last Edit: June 19, 2020, 02:48:03 pm by bplus »

Marked as best answer by SpriggsySpriggs on June 19, 2020, 11:20:50 am

FellippeHeitor

  • Guest
Re: _STARTDIR$ weirdness
« Reply #2 on: June 19, 2020, 03:08:25 pm »
I guess it has to do with whether "Start in" ("Iniciar em" in my pt-br screenshot) is set or left blank. Right-clicking your shortcut and choosing Properties returns something similar?

Another thing: you may want to use _CWD$ (current work dir) instead.

  [ You are not allowed to view this attachment ]  
« Last Edit: June 19, 2020, 03:11:05 pm by FellippeHeitor »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: _STARTDIR$ weirdness
« Reply #3 on: June 19, 2020, 03:22:59 pm »
Another thing: you may want to use _CWD$ (current work dir) instead.
The main reason I don't want to use that too much is because I'm afraid I'll forget and use a CHDIR in my program which will screw up all my PowerShell calls that I like using.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: _STARTDIR$ weirdness
« Reply #4 on: June 19, 2020, 03:24:18 pm »
Do you need meta commands to find the Source Folder for exe?
The $IF and $LET is just because I had it in a BM and was using that for keeping errors out of the IDE from a possible second declaration in an $INCLUDE
Shuwatch!

FellippeHeitor

  • Guest
Re: _STARTDIR$ weirdness
« Reply #5 on: June 19, 2020, 03:44:14 pm »
The main reason I don't want to use that too much is because I'm afraid I'll forget and use a CHDIR in my program which will screw up all my PowerShell calls that I like using.

Code: QB64: [Select]
  1. DIM SHARED startDir$
  2. startDir$ = _CWD$

Do that in the beginning of your program and you're golden. BTW, that's how _STARTDIR$ is generated at program startup in the c++ code:

Code: C++: [Select]
  1. //store _CWD$ for recall using _STARTDIR$ in startDir
  2.     startDir=qbs_new(0,0);
  3.     qbs_set(startDir,func__cwd());

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: _STARTDIR$ weirdness
« Reply #6 on: June 19, 2020, 03:48:45 pm »
I don't know why I didn't think of that. That's such a simple solution, too. Thanks!
Shuwatch!