Sign in to follow this  
Followers 0
blademonkey

#include Question

9 posts in this topic

I have a script that is including another au3 file. in the include file there's a piece of code that uses @scriptdir path which, when included into another script, ends up not being the intended path.

for instance, let's say we have :

\\server1\share\File1.au3

\\server2\share\file2.au3

we're including file1.au3 in file2.au3 so file2 will look like this

#include "\\server1\share\File1.au3"
[...]

and file1 looks like this:

$sFilename = @scriptdir & '\' & stringtrimright(@scriptname,3) & '.ini')
$sSection = "user1"
$sKey = "password"
$sPWD = iniread($sFilename, $sSection, $sKey,"")

When i compile file2, the path for @scriptdir is \\server2\share\ but i want to reference \\server1\share\ (so that i dont have to copy the file to every program folder that i have).

any recommendation would be appreciated.

thanks.


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

I do not know what the best solution to that would be, but I see that some smart folk are on the forum atm - so maybe this will be a timely bump.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

mmm could be me not thinking strait but i don't understand it ....

I would think that this should work since you hardcode server1 anyways:

File2.au3

$ServerPath = "\\server1\share"
#include "\\server1\share\File1.au3"

File1.au3

$sFilename = $ServerPath & '\' & stringtrimright(@scriptname,3) & '.ini')
$sSection = "user1"
$sKey = "password"
$sPWD = iniread($sFilename, $sSection, $sKey,"")

:D

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

mmm could be me not thinking strait but i don't understand it ....

I would think that this should work since you hardcode server1 anyways:

File2.au3

$ServerPath = "\\server1\share"
#include "\\server1\share\File1.au3"

File1.au3

$sFilename = $ServerPath & '\' & stringtrimright(@scriptname,3) & '.ini')
$sSection = "user1"
$sKey = "password"
$sPWD = iniread($sFilename, $sSection, $sKey,"")

:D

Well I'm not sure what you mean to do by adding the server path.

What I'm saying is that at compile time, the @scriptdir will point to the path for file2 (because i'm including the file1 code inside it) and not file1. What I would like to do is to reference, in some variable way (so i do not have to hardcode the location everytime), the path of for file1, again without hardcoding.

not possible?


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

When i compile file2, the path for @scriptdir is \\server2\share\ ...

You are broken already with that assumption.

<Insert favorite wise crack about assumptions here.>

The value of a macro like @ScriptDir IS NOT interpreted at all at compile time! The script is not being run while it is being "compiled", so no value is being substituted for the text "@ScriptDir". The text file is being parsed into something else that you wouldn't recognize if you could see it.

I think the best you'll get is some kind of "PreProcessor" to dynamically update the text of a static Global variable assignment just before you compile.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Alright, thanks for the correction on the assumption and pointing me in the right direction.

From looking at that thread it seems more complicated to code a solution than hardoding the path manually.

So i will deal.

Thanks.

-Blademonkey


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

Still don't understand why my provided solution wouldn't work .... :D

I was trying to get away from hardcoding a path in the include file, as that path is subject to change.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0