Notifications
Clear all
[Closed] include with doesFileExist
Dec 05, 2017 10:13 am
Hi!
Let’s say we have a script.ms file located either under $scripts or $userScripts
I need to check if one of them exists, then include it, otherwise, include the other one.
How should I do?
4 Replies
1 Reply
(
script01 = "path 1"
script02 = "path 2"
if doesFileExisst script01 then
fileIn script01
else
(
if doesFileExisst script02 then
fileIn script02
else
messagebox "Both scritps are missing" title:""
)
)
Dec 05, 2017 10:13 am
Thank you Kostadin, this brought me further.
What if I have a variable, and want to set it to a path: if it exists.
Something like mypath = $scripts\myfolder (if it exists) else $userScripts\myfolder
Dec 05, 2017 10:13 am
(
-- credit to James Haywood
function DoesFolderExist f create:false =
(
local val
val = if (doesFileExist f) and (getfileattribute f #directory) then true else false
if not val and create then
(
val = makeDir f
)
val
)
userScriptsDir = (pathConfig.GetDir #userscripts)
scriptsDir = (pathConfig.GetDir #scripts)
folderName = "myfolder"
validPath = undefined
if DoesFolderExist (curPath = userScriptsDir + "\\" + folderName + "\\") then
(
validPath = curPath
)
else
(
if DoesFolderExist (curPath = scriptsDir + "\\" + folderName + "\\") then
(
validPath = curPath
)
else
(
messagebox "Folders not exist" title:""
)
)
format "validPath: %
" validPath
)
Dec 05, 2017 10:13 am
This is how I did
if doesFileExist "$scripts\\MyScriptLocation\\" then scriptLoc = (GetDir #Scripts) else scriptLoc = (GetDir #userScripts)
filein (scriptLoc + "\MyScriptLocation\MyScript.ms")
I am not really sure about the difference between fileIn and include, but depending on the situation, include seems to work sometimes.