Author |
Topic: *CD in Android (Read 473 times) |
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
*CD in Android
« Thread started on: Jan 14th, 2016, 2:55pm » |
|
Android doesn't have the concept of 'current working directory' that Windows and Linux have. The *CD command 'works' (that is, you can change the directory and it will display what you changed it to) but it doesn't actually control where files are read from or written to!
Put another way, if you don't specify an absolute path for a file Android uses a default directory which is unrelated to the directory that *CD displays (and is not straightforward to discover).
The practical consequence is that you should always specify an absolute path if you want your programs to run properly under Android. It is in any case bad practice to assume that the 'current directory' is initially where your program was loaded from, because even under Windows and Linux it may not be.
So for example if you currently use OPENIN("filename") change it to OPENIN(@dir$+"filename"). This should ensure compatibility across all platforms.
Richard.
|
|
Logged
|
|
|
|
jgharston
New Member
member is offline


Posts: 12
|
 |
Re: *CD in Android
« Reply #1 on: Oct 13th, 2017, 11:28pm » |
|
on Jan 14th, 2016, 2:55pm, Richard Russell wrote:| So for example if you currently use OPENIN("filename") change it to OPENIN(@dir$+"filename"). This should ensure compatibility across all platforms. |
|
Except if you're writing a file navigator, as was the first bit of "real code" I was experimenting with today. Eg:
OSCLI "CD "+destination$ *.*.* INPUT "File: "A$ CHAIN A$
Non-Android (ok, I've only tried Windows, RISCOS and BBC) chain the file you can see, Android tries to find a file hidden behind the mystery door (I think in /mnt).
Doing CHAIN @dir+A$ results in always looking for a file in the directory the executing program was launched from, not the one you're looking at.
...more investigation needed.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: *CD in Android
« Reply #2 on: Oct 14th, 2017, 08:32am » |
|
on Oct 13th, 2017, 11:28pm, jgharston wrote:| Doing CHAIN @dir+A$ results in always looking for a file in the directory the executing program was launched from |
|
Well, not "was launched from" but "is stored in" (which is what @dir$ means). You took my comment too literally: when suggesting @dir$+filename$ I was of course using that as an example of a fully-qualified (absolute) path. You could use @usr$ or @tmp$ or @lib$ - or a path specified relative to one of those - and it would work just as well. It's just that in Android you cannot pass a relative path (which by definition means 'relative to the Current Directory') since there is no 'Current Directory'.
There is no need for any "investigation", that's how Android works. It's good practice to use absolute paths on all platforms so it shouldn't be an onerous requirement.
Richard.
|
|
|
|
|