Escape Sequence

BlitzMax Forums/BlitzMax Programming/Escape Sequence

Banshee(Posted 2007) [#1]
I'm having trouble setting the current directory whilst using the OS X version of Blitz Max because of an escape string conflict.

I wish to store a file in the users home/library/preferences, the home directory is usually accessed via a tilde character, which in BlitzMax is an escape sequence, putting a single tilde on the path makes the compiler state that it is a bad escape sequence string.

Putting two tilde characters tries to change the directory to a folder with two tilde's in it. At least I think that's why it's failing.

Am I doing something wrong, is there another way to access the home folder bearing in mind the user folder is always named differently?

I have tried using chr(126) to send the ASCII code in place, but that also fails - although with a single chr(126) the program does still compile (id expect this to work) but still fails to set the home directory.

This hack of readdir.bmx should show the problem i'm having.

' readdir.bmx

DebugLog ChangeDir(Chr(126)+"/Library/Preferences/")
	'Returns 0
DebugLog ChangeDir(Chr(126)+Chr(126)+"/Library/Preferences/")
	'Returns 0
'DebugLog ChangeDir("~/Library/Preferences/")
	'Wont compile, 'bad escape sequence in string'
DebugLog ChangeDir("~~/Library/Preferences/")
	'Returns 0

dir=ReadDir(CurrentDir())

If Not dir RuntimeError "failed to read current directory"

Repeat
	t$=NextFile( dir )
	If t="" Exit
	If t="." Or t=".." Continue
	Print t	
Forever

CloseDir dir



Who was John Galt?(Posted 2007) [#2]
The string with the double tilde you tried should give you the equivalent of a single tilde char in your string. It's just not being interpreted, for some reason. Have you tried just making a direct system call to change the directory? Not ideal I know.


DJWoodgate(Posted 2007) [#3]
No Mac here, but a forum search revealed...

http://blitzmax.com/Community/posts.php?topic=66311

Checkout Bruceys post and his module. Sounds like it might help.


Brucey(Posted 2007) [#4]
And the environment variable HOME might help too (although this isn't always guaranteed to point to the right place - since users can change that when they want).

> echo ~
/Users/brucey

> echo $HOME
/Users/brucey


:-)


Brucey(Posted 2007) [#5]
But your best bet is via the system APIs... as they are presumed always to point to the right place.

As Mr Woodgate mentions, this module can get you the home folder, via the APIs no less : http://brucey.net/programming/blitz/index.php#bahvolumes

I suppose I could add support directly for the Preferences folder (also available via the API, rather than having to tag /xxxxx/xxxx on the end of the home folder name)

;-)


Banshee(Posted 2007) [#6]
Thank Brucey i'll check that out later today.

I do sometimes despair at Blitz Max... Not even able to change a directory now!? *bangs head on wall until it implodes*.

Things where so simple once...