KenDown wrote: ↑Wed 21 Oct 2026, 03:46
My program (which is compiled) is on my D: drive, but can equally well run off a USB stick or other portable drive, so access permissions should be fine.
If your program is running from a USB stick you would surely not want to write to the stick and risk corrupting it, for example if the user were to unplug it without first going through the 'safely remove' procedure? That sounds like a classic case where you would want @dir$ to be read-only.
Is this some deliberate restriction on @dir$?
Generally a program will be stored in a location which is not normally writable, not least for security reasons. Being able to modify a program or its support files (e.g. libraries/DLLs) without administrative privileges would make it trivially easy for malware to infect it, or for accidental corruption to damage it.
That's why, in Windows, there are areas of the file system called
Program Files, which is not user-writable, and
Program Data (for non-user specific data) and
Application Data (for user-specific data), which are; other operating systems have similar divisions in the file system.
So, yes, ensuring that a program is stored somewhere non-writable is "deliberate".
Is there a work-around?
Why would you want a "work-around" for a key security feature that protects you and your users? If you need to write to the directory containing your program then do it 'As Administrator' (that's how installers work).
That's not to say that you can't store your program in a user-writable location, you can, but it's extremely risky and should be done only if you are fully aware of the potential consequences.
* commands don't usually need them unless there is a space or some other "illegal" character in the filename.
...or in the path. That's the crucial point:
@dir$ (and
@tmp$,
@usr$) will
very commonly contain characters which require the entire path to be enclosed in quotes. And of course you have no idea what they will be on the target machine running your program. So whenever using one of those pre-defined path variables you must always add quotes.
All this is standard stuff, and much of it applies to other programming languages too.