Page 1 of 1 1
Topic Options
#213344 - 2018-06-06 12:12 AM Can I pass a "path/filename" to a Kix File
JustMark Offline
Fresh Scripter

Registered: 2013-03-20
Posts: 7
Loc: Arizona
I would like to know if Kix can be passed a path/filename. I have a text file that gets created by the users on their local machines. The folder it ends up in is always different.
If I have the path/filename, can I pass it to a Kix program?

Thanks,
Mark

Top
#213345 - 2018-06-06 12:48 AM Re: Can I pass a "path/filename" to a Kix File [Re: JustMark]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Two ways:
 Code:
Kix32 myscript.kix $Varname="This is the value"
This will define a $Varname GLOBAL variable that you can directly access in your script. The problem with this approach is that if the variable isn't supplied and you have Explicit=On, your script will fail.
 Code:
Kix32 myscript.kix --f:"this is the file path"
This requires a bit more effort, but is usually preferred. Here's how you use it:
 Code:
$aTemp = GetCommandLine(1)  ; command line as array.
; elements 0 and 1 are "kix32.exe" and the script name, so start with 2.
For $X = 2 to UBound($aTemp)
  If InStr($aTemp[$X], '--f:')        ; found the filespec directive
    $FileSpec = SubStr($aTemp[$X], 5) ; position 5 and beyond is the filespec value
  EndIf
Next
At this point, your $Filespec variable will either contain everything after "--f:" or will be empty. Works well with Explicit=On. You could eliminate the "--f:" part and assume that the argument is the filespec, but we all know what happens when we assume. Using the --f:path format forces the definition to be intentional rather than assumed.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1005 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.171 seconds in which 0.134 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org