Thread overview | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 21, 2016 full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Is there a way to get the full path of the current source file? Something like: __FILE_FULL_PATH__ I'm asking because I'm rewriting a batch script in D, meant to be ran with rdmd. However, the script needs to know it's own path. The original batch script uses the %~dp0 variable for this, but I'm at a loss on how to do this in D. Since rdmd compiles the executable to the %TEMP% directory, thisExePath won't work. BATCH ----- echo "Directory of this script is " %~dp0 DLANG ----- import std.stdio; int main(string[] args) { writeln("Directory of this script is ", ???); } |
July 21, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan Marler | On Thursday, 21 July 2016 at 19:54:34 UTC, Jonathan Marler wrote:
> thisExePath won't work.
won't? what this means?
this work on my windows
import std.file: thisExePath;
import std.stdio: writeln;
void main()
{
writeln(thisExePath());
}
|
July 21, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to zabruk70 | On Thursday, 21 July 2016 at 22:28:39 UTC, zabruk70 wrote:
> won't? what this means?
That gives the path to the .exe but he wants the path to the .d.
But why? I would think the current working directory is probably adequate and that's easy to get...
|
July 21, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan Marler | On 7/21/16 3:54 PM, Jonathan Marler wrote:
> Is there a way to get the full path of the current source file?
> Something like:
>
> __FILE_FULL_PATH__
>
> I'm asking because I'm rewriting a batch script in D, meant to be ran
> with rdmd. However, the script needs to know it's own path. The
> original batch script uses the %~dp0 variable for this, but I'm at a
> loss on how to do this in D. Since rdmd compiles the executable to the
> %TEMP% directory, thisExePath won't work.
>
> BATCH
> -----
> echo "Directory of this script is " %~dp0
>
>
> DLANG
> -----
> import std.stdio;
> int main(string[] args) {
> writeln("Directory of this script is ", ???);
> }
Sure seems like an unwanted limitation.
rdmd does forward all dmd options, but there isn't really an option to say "put the exe in the source path".
You should file an enhancement.
-Steve
|
July 21, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Thursday, 21 July 2016 at 22:33:39 UTC, Adam D. Ruppe wrote:
> On Thursday, 21 July 2016 at 22:28:39 UTC, zabruk70 wrote:
>> won't? what this means?
>
> That gives the path to the .exe but he wants the path to the .d.
>
> But why? I would think the current working directory is probably adequate and that's easy to get...
I explain in the original post. Any ideas Adam? Thanks in advance.
|
July 21, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thursday, 21 July 2016 at 22:39:45 UTC, Steven Schveighoffer wrote:
> On 7/21/16 3:54 PM, Jonathan Marler wrote:
>> Is there a way to get the full path of the current source file?
>> Something like:
>>
>> __FILE_FULL_PATH__
>>
>> I'm asking because I'm rewriting a batch script in D, meant to be ran
>> with rdmd. However, the script needs to know it's own path. The
>> original batch script uses the %~dp0 variable for this, but I'm at a
>> loss on how to do this in D. Since rdmd compiles the executable to the
>> %TEMP% directory, thisExePath won't work.
>>
>> BATCH
>> -----
>> echo "Directory of this script is " %~dp0
>>
>>
>> DLANG
>> -----
>> import std.stdio;
>> int main(string[] args) {
>> writeln("Directory of this script is ", ???);
>> }
>
> Sure seems like an unwanted limitation.
>
> rdmd does forward all dmd options, but there isn't really an option to say "put the exe in the source path".
>
> You should file an enhancement.
>
> -Steve
An option for rdmd would be good, but then requires the user to call rdmd in a particular way. It doesnt allow the script itself know where it lives, which is needed in my case.
|
July 21, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thursday, July 21, 2016 18:39:45 Steven Schveighoffer via Digitalmars-d- learn wrote:
> On 7/21/16 3:54 PM, Jonathan Marler wrote:
> > Is there a way to get the full path of the current source file? Something like:
> >
> > __FILE_FULL_PATH__
> >
> > I'm asking because I'm rewriting a batch script in D, meant to be ran with rdmd. However, the script needs to know it's own path. The original batch script uses the %~dp0 variable for this, but I'm at a loss on how to do this in D. Since rdmd compiles the executable to the %TEMP% directory, thisExePath won't work.
> >
> > BATCH
> > -----
> > echo "Directory of this script is " %~dp0
> >
> >
> > DLANG
> > -----
> > import std.stdio;
> > int main(string[] args) {
> >
> > writeln("Directory of this script is ", ???);
> >
> > }
>
> Sure seems like an unwanted limitation.
>
> rdmd does forward all dmd options, but there isn't really an option to say "put the exe in the source path".
>
> You should file an enhancement.
It would be pretty terrible actually to put the executable in the source path, and in many cases, the user wouldn't even have the permissions for it. For instance, what if the script were in /usr/local/bin? They won't have the permissions for the executable to end up there, and it would just cause a bunch of clutter in /usr/local/bin, since you'd get a new executable every time it decided that it needed to rebuild it (and you wouldn't want it to delete the executable every time, otherwise it would have to rebuild it every time, making it so that it would _always_ have to compile your script when it runs instead of just sometimes). Right now, the executable ends up in a temp directory, which makes a lot of sense.
Maybe it would make sense to have such a flag for very rare cases, but in general, it seems like a terrible idea.
- Jonathan M Davis
|
July 21, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan Marler | On Thursday, July 21, 2016 19:54:34 Jonathan Marler via Digitalmars-d-learn wrote:
> Is there a way to get the full path of the current source file? Something like:
>
> __FILE_FULL_PATH__
>
> I'm asking because I'm rewriting a batch script in D, meant to be ran with rdmd. However, the script needs to know it's own path. The original batch script uses the %~dp0 variable for this, but I'm at a loss on how to do this in D. Since rdmd compiles the executable to the %TEMP% directory, thisExePath won't work.
>
> BATCH
> -----
> echo "Directory of this script is " %~dp0
>
>
> DLANG
> -----
> import std.stdio;
> int main(string[] args) {
> writeln("Directory of this script is ", ???);
> }
Well, while it might not be what you want, the obvious solution is to just compile it as an executable and put that where you want rather than making it a script.
- Jonathan M Davis
|
July 22, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan Marler | On Thursday, 21 July 2016 at 22:47:42 UTC, Jonathan Marler wrote:
> I explain in the original post. Any ideas Adam? Thanks in advance.
But why does the batch script use it? Since you are rewriting anyway, maybe you can find an easier/better way to achieve the goal.
|
July 22, 2016 Re: full path to source file __FILE__ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Friday, 22 July 2016 at 01:52:57 UTC, Adam D. Ruppe wrote:
> On Thursday, 21 July 2016 at 22:47:42 UTC, Jonathan Marler wrote:
>> I explain in the original post. Any ideas Adam? Thanks in advance.
>
> But why does the batch script use it? Since you are rewriting anyway, maybe you can find an easier/better way to achieve the goal.
The script depends on other files relative to where it exists on the file system. I couldn't think of a better design to find these files then knowing where the script exists, can you?
|
Copyright © 1999-2021 by the D Language Foundation