Page 1 of 1
Directory structure in CMDR-DOS
Posted: Thu Aug 18, 2022 4:20 pm
by ZeroByte
One of the things lacking in CMDR-DOS is the ability to get the current directory name.
If I'm wrong about this, someone please point me in the right direction and ignore the rest of this post. ?
This isn't a perfect solution, but I think it might give programs something to work with in terms of directory handling. Currently, whenever you load $, the header line contains the volume/disk name. Wouldn't it make more sense to change this to be the name of the current directory? It doesn't need to be the full path, just the name of the current folder, or / if it is the root directory. This way, a program that needs to figure out PWD can use this to know the current directory, and if .. is present in $=D then it can build the absolute path by walking up to the root and prepending parent_dir_name/ to the path string. This is doable because currently, the directories '.' and '..' only appear when you are in a subdirectory.
Thoughts?
Directory structure in CMDR-DOS
Posted: Thu Aug 18, 2022 4:49 pm
by ZeroByte
I think this will be useful for programs because I suspect that the most common use case for X16 is that people will have an SD card with all of their programs "installed" in subfolders. If a program wants to feature directory browsing, it would need to have some clue about what folder it is located in so that it can always "CD" back into that folder for any files it uses such as INI files, assets, etc., while still being able to walk the entire FS for whatever purpose.
Directory structure in CMDR-DOS
Posted: Thu Aug 18, 2022 6:28 pm
by TomXP411
On 8/18/2022 at 9:20 AM, ZeroByte said:
One of the things lacking in CMDR-DOS is the ability to get the current directory name.
If I'm wrong about this, someone please point me in the right direction and ignore the rest of this post. ?
This isn't a perfect solution, but I think it might give programs something to work with in terms of directory handling. Currently, whenever you load $, the header line contains the volume/disk name. Wouldn't it make more sense to change this to be the name of the current directory? It doesn't need to be the full path, just the name of the current folder, or / if it is the root directory. This way, a program that needs to figure out PWD can use this to know the current directory, and if .. is present in $=D then it can build the absolute path by walking up to the root and prepending parent_dir_name/ to the path string. This is doable because currently, the directories '.' and '..' only appear when you are in a subdirectory.
Thoughts?
Honestly, I'd rather see a PWD command, or see CD return the current directory. I don't want to have to load the whole directory, just to see what the current directory is.
So CD by itself would return the current directory, like this:
10 OPEN 15,8,15,"CD"
20 INPUT#15,D$
This would imply that CD with an argument returns the newly selected directory, which I'm fine with.
Directory structure in CMDR-DOS
Posted: Thu Aug 18, 2022 6:41 pm
by ZeroByte
I think CD with an argument needs to return the usual "CODE,MESSAGE,TRACK,SECTOR" result, since CD can fail for various reasons....
It isn't breaking anything if a no-argument CD is tantamount to saying "please give me the PWD" so you wouldn't expect anything OTHER than success, as it's essentially a no-op as far as CD is concerned.
But point well taken regarding the directory listing. Although, I was definitely thinking that it would be nice to at least have the current directory's name (not full path) available because if you do a CD .. without knowing what folder you were in, there wouldn't really be any way to know where to go back down into later if you needed to... but having a PWD command of some sort would be good to have for the general case, and you could just use that before stepping out of the directory you began in at runtime.
Directory structure in CMDR-DOS
Posted: Fri Aug 19, 2022 12:03 am
by TomXP411
On 8/18/2022 at 11:41 AM, ZeroByte said:
I think CD with an argument needs to return the usual "CODE,MESSAGE,TRACK,SECTOR" result, since CD can fail for various reasons....
It isn't breaking anything if a no-argument CD is tantamount to saying "please give me the PWD" so you wouldn't expect anything OTHER than success, as it's essentially a no-op as far as CD is concerned.
But point well taken regarding the directory listing. Although, I was definitely thinking that it would be nice to at least have the current directory's name (not full path) available because if you do a CD .. without knowing what folder you were in, there wouldn't really be any way to know where to go back down into later if you needed to... but having a PWD command of some sort would be good to have for the general case, and you could just use that before stepping out of the directory you began in at runtime.
There's certainly no harm in doing both. Have the default directory in the directory header, along with a separate "get directory" command.
I'm sure that there is a way to read the current directly directly from RAM; I just haven't bothered to look through the code to figure out where that is stored. If you know where the variable is, then it's just a matter of reading it, rather than using a DOS command.
FYI, looking at the SD2IEC documentation, there is now PWD equivalent, as far as I can tell. Since SD2IEC's commands are based on the CMD hard drive, I'm assuming this isn't in the CMD command set, either.