QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: FilipeEstima on April 28, 2019, 05:51:10 pm

Title: How to properly find "documents" folder in any PC?
Post by: FilipeEstima on April 28, 2019, 05:51:10 pm
I am coding in a machine that has documents folder at D: drive, so whenever I have to get a file in that folder I use absolute path starting with D: - however, when the same program is ran at another PC where documents folder sits at C: drive, I get "Device unavailable". So, how can I properly determine the absolute path to the documents folder, that will allow the program to find it, no matter where it is running (by "no matter where" I mean any PC, any drive and any folder inside said PC)?

I suppose QB64 doesn't like use of system variable %documents%. I tried changing "D:documents" and the IDE complained. Is the only way to obtain the correct path in any computer via consulting Windows Registry?
Title: Re: How to properly find "documents" folder in any PC?
Post by: FellippeHeitor on April 28, 2019, 06:01:55 pm
Try:
Code: QB64: [Select]
  1. PRINT _DIR$("documents")
Title: Re: How to properly find "documents" folder in any PC?
Post by: Petr on April 28, 2019, 06:06:49 pm
Fellippe is faster :-D

My version: Path$ = ENVIRON$("homedrive") + ENVIRON$("homepath") + "\Documents"
Title: Re: How to properly find "documents" folder in any PC?
Post by: FellippeHeitor on April 28, 2019, 06:07:04 pm
Or maybe even:
Code: QB64: [Select]
  1. PRINT ENVIRON$("HOMEDRIVE") + ENVIRON$("HOMEPATH") + "\My Documents\"
Title: Re: How to properly find "documents" folder in any PC?
Post by: FellippeHeitor on April 28, 2019, 06:07:26 pm
Ah, Petr was faster this time.

Although _DIR$ is safer, as it gets info from the registry.
Title: Re: How to properly find "documents" folder in any PC?
Post by: Petr on April 28, 2019, 06:08:28 pm
No, you are first in thread :-D
Title: Re: How to properly find "documents" folder in any PC?
Post by: FilipeEstima on April 28, 2019, 07:22:41 pm
Thanks to both Fellippe and Petr, this is exactly what I needed. Although it doesn't work with all commands, since $EXEICON doesn't allow for string variable passed as argument :-(
Title: Re: How to properly find "documents" folder in any PC?
Post by: FellippeHeitor on April 28, 2019, 07:25:14 pm
Your icon should be in the same folder as your source code, or at least in a subfolder:

Code: QB64: [Select]
  1. $EXEICON:'./MyIcon.ico'

And it must be a literal because the icon is stored in the exe at compile time.
Title: Re: How to properly find "documents" folder in any PC?
Post by: FilipeEstima on April 28, 2019, 07:28:56 pm
I found out that the icon doesn't really need to be in the same folder or subfolder of the source. It can be anywhere in the computer, provided the path is correct. Just tried putting it on another drive on a long path and it was found by the IDE.
Title: Re: How to properly find "documents" folder in any PC?
Post by: FellippeHeitor on April 28, 2019, 07:43:40 pm
It will be found, sure. It's just weird to place it elsewhere.