Author Topic: How to properly find "documents" folder in any PC?  (Read 3611 times)

0 Members and 1 Guest are viewing this topic.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
How to properly find "documents" folder in any PC?
« 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?

FellippeHeitor

  • Guest
Re: How to properly find "documents" folder in any PC?
« Reply #1 on: April 28, 2019, 06:01:55 pm »
Try:
Code: QB64: [Select]
  1. PRINT _DIR$("documents")

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How to properly find "documents" folder in any PC?
« Reply #2 on: April 28, 2019, 06:06:49 pm »
Fellippe is faster :-D

My version: Path$ = ENVIRON$("homedrive") + ENVIRON$("homepath") + "\Documents"

FellippeHeitor

  • Guest
Re: How to properly find "documents" folder in any PC?
« Reply #3 on: April 28, 2019, 06:07:04 pm »
Or maybe even:
Code: QB64: [Select]
  1. PRINT ENVIRON$("HOMEDRIVE") + ENVIRON$("HOMEPATH") + "\My Documents\"

FellippeHeitor

  • Guest
Re: How to properly find "documents" folder in any PC?
« Reply #4 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.
« Last Edit: April 28, 2019, 06:08:44 pm by FellippeHeitor »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How to properly find "documents" folder in any PC?
« Reply #5 on: April 28, 2019, 06:08:28 pm »
No, you are first in thread :-D

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: How to properly find "documents" folder in any PC?
« Reply #6 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 :-(

FellippeHeitor

  • Guest
Re: How to properly find "documents" folder in any PC?
« Reply #7 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.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: How to properly find "documents" folder in any PC?
« Reply #8 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.

FellippeHeitor

  • Guest
Re: How to properly find "documents" folder in any PC?
« Reply #9 on: April 28, 2019, 07:43:40 pm »
It will be found, sure. It's just weird to place it elsewhere.