You are not logged in. [Log In] KiXtart.org website » Forums » KiXtart » Basic Scripting » pass file and path as a variable to the script Register User       Forum List       Calendar       FAQ
 Page 1 of 2 1 2 >
 Topic Options
 #145019 - 2005-08-08 02:00 PM pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK Hi - new to using KiXtart, but been looking at it on and off for a while: I want to be able to pass a file name and UNC path to the script as a variable $file, archive a copy of the file to an archive folder, and then depending on which directory it can from move it to the relevent remote site. For example, if it came from e:\dropin\london then it goes to the 'London' server, but if it came from the e:\dropin\paris the it goes to the Paris server. I'd like to use a SELECT... CASE startement, but how would I split down the directory? In DOS I can use the variable %~pd1 to pull out the path but how do I do that in KiXtart? I'm no programmer, but can do a little VBS/VB etc. Any assistance greatly appreciated. Edited by matthewh (2005-08-08 02:07 PM) Top  #145020 - 2005-08-08 02:17 PM Re: pass file and path as a variable to the script Richard H. Administrator Registered: 2000-01-24 Posts: 4945 Loc: Leatherhead, Surrey, UK Split will split things into an array so that you can pick the bits out of it.If you only want the very last element, InStrRev() will allow you to look back and find the last "\" in the string - everthing after that is the last element.For example, to find the last part of a path name:Code:$sPath="\\some\path\or\other"$sLastBit=SubStr($sPath,1+InStrRev($sPath,"\"))"Last bit of the path is '"+$sLastBit+"'"@CRLF Top
 #145021 - 2005-08-08 02:20 PM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK Ok - I'll have a play and let you know. Thanks for that. Top
 #145022 - 2005-08-08 02:26 PM Re: pass file and path as a variable to the script Richard H. Administrator Registered: 2000-01-24 Posts: 4945 Loc: Leatherhead, Surrey, UK Here is a method using Split(), useful if you need to get other elements of the path:Code:$sPath="\\some\path\London\file.txt"$sPathBits=Split($sPath,"\")$sFile=$sPathBits[UBound($sPathBits)]$sCity=$sPathBits[UBound($sPathBits)-1]"File name is '"+$sFile+"'"+@CRLF"City name is '"+$sCity+"'"+@CRLF Top  #145023 - 2005-08-08 02:32 PM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK Can I use the variable$file as the string to split? "$file" is used by the application that will call the KiXtart script - I can pass it to a DOS batch file as %1 etc, can I use any variable name in KiXtart or should I use$file? Top
 #145024 - 2005-08-08 02:35 PM Re: pass file and path as a variable to the script Richard H. Administrator Registered: 2000-01-24 Posts: 4945 Loc: Leatherhead, Surrey, UK BTW, if you haven't found it already, there are two ways to pass the path to the script.Set an environment variable and use it directly in the script.Pass it explicitly on the command line e.g. "kix32.exe $sPath=c:\foo\bar\London\file.txt myscript.kix" Top  #145025 - 2005-08-08 02:41 PM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK Thanks Richard. It's the Explicit one I need but will use$file to pass it to $sPath, i.e."kix32.exe$sPath=$file" - if that'll work!The user manual isn't all that clear to a non-programmer but I'll get there. Top  #145026 - 2005-08-08 02:59 PM Re: pass file and path as a variable to the script Richard H. Administrator Registered: 2000-01-24 Posts: 4945 Loc: Leatherhead, Surrey, UK Your application may get confused if it is expanding the variables in the line - you may need to escape the "$" on the "$sPath" to ensure that your app does not expand it.What is the application that you are using to call the KiXtart script? Top  #145027 - 2005-08-08 03:07 PM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK It's called YGF, but it doesn't use the variable - it just passes it TO whatever it calls - so that could be another app, or a batch file or in this case a script. I don't need to use it at all. It scans a set of folders every 60 seconds and performs functions of whatever it finds - mostly sends emails, but will do more. I could write a different batch file for each folder but wanted to simplify it and have it call one script. I don't even know if it'll work. Top  #145028 - 2005-08-10 03:18 PM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK OK - I've been pulling my hair out with this now for a while. Tried VBS - n'good. Tried Robocopy in a batch file, - reads the %1 variable with a trailing "\" after the file name (and if I break it doen with %~pd etc it still fails) so that's no use. Back to KiXtart. I now have a different way of looking at it:Copy$file "c:\ftp Archive\"Select Case Instr($file, "Peterborough") COPY$file \\xxx.xxx.xxx.xxx\DropIn\Peterborough\ Case Instr($file, "Portsmouth") copy$file \\xxx.xxx.xxx.xxx\DropIn\Portsmouth\ Case Instr($file, "Sunderland") copy$file \\xxx.xxx.xxx.xxx\DropIn\Sunderland\ Case Instr($file, "Hartlepool") copy$file \\xxx.xxx.xxx.xxx\DropIn\Hartlepool\ Case Instr($file, "FTP_TEST") copy$file \\xxx.xxx.xxx.xxx\DropIn\EndSelectIt's called from a batch file - runkix.bat and contains the line: kix32.exe $file=%1 c:\scripts\Filecopy.kix.I've tried kix32.exe$file=^%1 c:\scripts\Filecopy.kix but that fails.The conf file for YGF contains the line:LaunchApplication=Runkix.bat $file And$file is where the path and filename is stored and it is this I have to pass to the KiXtart script. Tried calling the script direct from the conf file but it don't work. Any ideas anyone? Top
 #145029 - 2005-08-10 04:12 PM Re: pass file and path as a variable to the script Richard H. Administrator Registered: 2000-01-24 Posts: 4945 Loc: Leatherhead, Surrey, UK You have spaces in the path name.In your batch file, try:Code:kix32.exe $file="%1" c:\scripts\Filecopy.kixAdd some diagnostics in the script so you can see what is going on. You can use RedirectOutput() to write the output to a file if the task runs under a service. Top  #145030 - 2005-08-10 04:17 PM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK I put those spaces in cos it didn't work without anyway, but hadn't tried with "" - doing it now. Top  #145031 - 2005-08-10 05:07 PM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK Nope. Still no joy - is there anything on Win2003 Server that might cause problems? Any lockdowns and so on? I've checked all the permissions, the batch/kix files run fine if I run them manually, just not if they are called by YGF. Kinda frustrating really. Just going to try it on W2000 Server. Edited by matthewh (2005-08-10 05:08 PM) Top  #145032 - 2005-08-10 07:30 PM Re: pass file and path as a variable to the script Witto MM club member Registered: 2004-09-29 Posts: 1828 Loc: Belgium Maybe you can write a script that also verifies if files were copied to the source folders?Code:Break OnDim$arrPlaces[], $strPlace,$strFilename$arrPlaces = "London", "Paris"While @ERROR = 0 For Each$strPlace in $arrPlaces$strFilename = Dir("e:\dropin\" + $strPlace) While$strFilename <> "" AND @ERROR = 0 If $strFilename <> "." AND$strFilename <> ".." If Exist("\\" + $strPlace + "\Rest\Of\ThePath" + "\" +$strFilename) Del "\\" + $strPlace + "\Rest\Of\ThePath" + "\" +$strFilename EndIf Move "e:\dropin\" + $strPlace + "\" +$strFilename "\\" + $strPlace + "\Rest\Of\ThePath" EndIf$strFilename = Dir() Loop Next Sleep 60Loop Top
 #145033 - 2005-08-10 10:46 PM Re: pass file and path as a variable to the script Lonkero KiX Master Guru Registered: 2001-06-05 Posts: 22303 Loc: OK your code looks fine.more than fine.I like tab alignment. k, just add some:if @error beep "Error on Del: " @error " - " @serror ? sleep 2 endifkinda line right after the del. _________________________ !download KiXnet Top
 #145034 - 2005-08-11 10:34 AM Re: pass file and path as a variable to the script Richard H. Administrator Registered: 2000-01-24 Posts: 4945 Loc: Leatherhead, Surrey, UK That's great, but you are missing the point.The (current) problem is that the batch/script is not getting executed.It needs some debug code added to both to confirm that they are actually being called at all, and what the parameter is if appropriate.Personally I'd dump YGF, code the new file detection in KiXtart and run it as a scheduled task. Top
 #145035 - 2005-08-11 10:58 AM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK Unfortunately - can't dump YGF, as it does other stuff as well. I'm convinced it's Windows 2003 Server - I ran it on my test W2k server her and it worked fine. (Hate to say it but if it was on Unix I'd have had it done last Friday) Top
 #145036 - 2005-08-11 11:08 AM Re: pass file and path as a variable to the script Witto MM club member Registered: 2004-09-29 Posts: 1828 Loc: Belgium What is %1?Can you put something like:Code:ECHO %1PAUSEkix32.exe \$file="%1" c:\scripts\Filecopy.kixin your batch file? Top
 #145037 - 2005-08-11 11:13 AM Re: pass file and path as a variable to the script matthewh Fresh Scripter Registered: 2005-08-08 Posts: 10 Loc: Peterborough, UK if I run the script and send the output to a text file it's fine. It's all where it should be, and I found out late last night running Sysinternal's TCPView that it seems to open a connetion to my test server there to copy the files then sits in a TIME_WAIT, but if I run it manually or on my Windows 2000 server I get ESTABLISHED on the connection. There's a handy open window here that it might fit through...... Top
 #145038 - 2005-08-11 01:17 PM Re: pass file and path as a variable to the script Witto MM club member Registered: 2004-09-29 Posts: 1828 Loc: Belgium Can you maybe give some example of what YGF is returning and is being used as %1 in your batch file. Just trying to get a better understanding of your problem. Top
 Page 1 of 2 1 2 >

Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart
 Hop to: KiXtart ------   Kixforms   KiXtart FAQ & How to's   Basic Scripting   Advanced Scripting   COM Scripting   Suggestions   BetaRepository ------   KiXtart Learning
 Shout Box
 Who's Online 1 registered (Allen) and 150 anonymous users online.
 Newest Members Hdrthtsr19956, Kylie99, msmile042, rayd8, HardKn0X 17597 Registered Users

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

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