Finding Home folder in FB

Linux specific questions.
Post Reply
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Finding Home folder in FB

Post by Dinosaur »

Hi All

In my code I usually specify the Paths in presets.bi as follows.

Code: Select all

Paths.Root      = "/home/dinosaur/hmi/"
Paths.Config    = Paths.Root + "control/"
Paths.Font      = Paths.Root + "fonts/"
Paths.Photo     = Paths.Root + "bitmaps/"
Paths.Text      = Paths.Root + "text/"
Paths.Report    = Paths.Root + "reports/"
Paths.Backups   = Paths.Root + "safekeep/"
This works fine whilst I am the only user of that program.
However it is NOT if I want to share what I have done.

I have tried a number of ways to "find" the home folder from within FB, but with no success.
Tried Shell "cd ~" and then CurDir still specifies the previous folder.

Is there a way to "find" the home folder, so that I can name my Paths.Root ??

Regards
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Finding Home folder in FB

Post by MrSwiss »

For multi-user peruse, I'd split the stuff into:
  • user related (configuration related, e.g. rights of access)
  • program related (resources needed by prog. to run)
In WIN you have UserName system variable, to make a "user specific path".
Use: Environ statement, to "get it".
(should have something similar, in every modern OS)
Resources can be placed below program's path (using ExePath statement).
(aka: once only stored, for all users the same, to save storage space)

Just some ideas ...

Code: Select all

' on CLI, something like
ChDir "/home/%username%/hmi/"
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Finding Home folder in FB

Post by badidea »

echo $HOME

Or, better:

Code: Select all

print environ("HOME")
freeBASIC does not understand "~"

Code: Select all

print chdir("~/") '<-- FAIL
print curdir()
print chdir("/home/badidea/testproject") '<-- OK
print curdir()

dim as string fileName = "~/testproject/hello.bas" '<-- FAIL
'fileName = "/home/badidea/testproject/hello.bas" '<-- OK
dim as integer fileNum = freeFile
if open(fileName, for input, as #fileNum) = 0 then
	while not eof(fileNum)
		dim as string text
		line input #fileNum, text
		print text
	wend
else
	print "error opening: " + fileName
end if
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: Finding Home folder in FB

Post by Dinosaur »

Hi All

Many thanks for the replies.
The echo $HOME was an immediate fix, but interested in persuing MrSwiss suggestions
of separating the program access & dependant files.

@badidea , I have sent you a PM re HS110

Regards
Post Reply