View Full Version : Get imported script dir


ajp_anton
29th August 2019, 04:24
In this example:

import("D:\somefolder\somefunction.avsi")

somefunction.avsi contains a function that loads images from that same folder. I'd like this setup to be portable, meaning I can move and rename the folder to different locations. But the function there assumes the current working dir is where the loading script is. Is there a way inside that function to know where its script is actually located?

ScriptDir() returns the location of the importing script.

StainlessS
29th August 2019, 10:41
# E:\main.avs

import("D:\somefolder\somefunction.avsi")




# D:\somefolder\Somfunction.avsi # should maybe be .avs but dont matter

#Imagesource(".\DQ-Tools.jpg",end=0) # OK

D=ScriptDir
RT_DebugF("ScriptDir='%s'",D)

Imagesource(D + "\" + "DQ-Tools.jpg",end=0) # OK


EDIT:
ScriptDir() appends trailing backslash, [not sure if avs 2.60 std does that], note Exist(ScriptDir()) would fail due to trailing backslash, must remove if test Exist()]
Adding "\" or not dont seem to matter [both work 'D:\somefolder\DQ-Tools.jpg' and 'D:\somefolder\\DQ-Tools.jpg' (at least they work in Avs+ and Win7) ].

00000165 0.06108138 [3884] RT_DebugF: ScriptDir='D:\somefolder\'


EDIT: Avs 2.60 std also appends backslash to scriptDir() and double backslash also works same as avs+. [at least on Win7, not tested on XP]