#140487 - 2005-05-27 07:08 PM
Split Right?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
I am doing a directory scan of a user’s folder looking for the following file, which has the date imbedded in the file name. I want to just look at files with today’s date. Am I using the split command wrong? Because the results of this script is _36_13.nbf, the last 10 characters of the file name and not the last 10 characters from the @ left.
C:\>kix32 FileDate.kix $FN="diagindex_TS-CTXFIA01_2005_05_26@07_36_13.nbf"
Code:
$sArray = Split ($FN,"@") $x = Right ($sArray[0], 10) ? $x
|
|
Top
|
|
|
|
#140488 - 2005-05-27 07:17 PM
Re: Split Right?
|
NeedANewJob
Fresh Scripter
Registered: 2005-04-01
Posts: 23
|
Your code works for me. You might want to check your version of KiXtart.
|
|
Top
|
|
|
|
#140489 - 2005-05-27 07:24 PM
Re: Split Right?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
KiXtart 2001 4.22
|
|
Top
|
|
|
|
#140490 - 2005-05-27 07:29 PM
Re: Split Right?
|
NeedANewJob
Fresh Scripter
Registered: 2005-04-01
Posts: 23
|
Hmmm... Weird. When I originally tested your code I put the $FN assignment in the script rather than passing it on the command line. I just tried it again passing it in the way you're doing it, and now I see the same thing as you do. Bizarre!
|
|
Top
|
|
|
|
#140491 - 2005-05-27 07:31 PM
Re: Split Right?
|
NeedANewJob
Fresh Scripter
Registered: 2005-04-01
Posts: 23
|
It has something to do with the "@" sign. I changed it to "#" and it works fine... Maybe it thinks you're trying to use a macro?
|
|
Top
|
|
|
|
#140492 - 2005-05-27 07:33 PM
Re: Split Right?
|
NeedANewJob
Fresh Scripter
Registered: 2005-04-01
Posts: 23
|
Could you split by "_" and then concatenate $sArray[2], $sArray[3], and $sArray[4]?
|
|
Top
|
|
|
|
#140494 - 2005-05-27 07:47 PM
Re: Split Right?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
That was easy enough to try and it worked. Thanks.
|
|
Top
|
|
|
|
#140495 - 2005-05-27 08:05 PM
Re: Split Right?
|
NeedANewJob
Fresh Scripter
Registered: 2005-04-01
Posts: 23
|
Hanging me head in shame... :-(
I should have thought of that!
|
|
Top
|
|
|
|
#140496 - 2005-05-27 10:08 PM
Re: Split Right?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
Just to show you all how crazy I am, - actually when you only know enough to be dangerous, but not enough to be proficient, you tend to do everything the hard way – here is the finished product. I’m sure there could have been a better way.
Step 1. get a list of users on a Citrix server 2. get the user’s home directory 3. search for files from a specific server 4. use kiXtart to search the file name for a specific date 5. and print out the file name with full path to the users home directory.
Command for /f "skip=1 tokens=1-2 delims=> " %i in ('quser') do @for /f "tokens=1-3 delims= " %k in ('net user %i /domain ^| find /i "home"') do @for /f %n in ('@dir %m\*.* /s /b ^| find /i "ctxfia"') do @kix32 FileDate.kix $FN="%n" $DLF="2005_05_27"
KiXtart Code:
$Myarray = Split($FN,"@@") $x = RIGHT($Myarray[0], 10) If $x = $DLF ? $FN EndIf
|
|
Top
|
|
|
|
#140498 - 2005-05-27 10:45 PM
Re: Split Right?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
I’m all for doing things the easiest way, just don’t know how. How could I use KiXtart to do what a FOR command will do?
|
|
Top
|
|
|
|
#140499 - 2005-05-27 10:57 PM
Re: Split Right?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You should read through the manual. KiXtart provides the several ways to perform looping oprations. Kixtart also provides file reading and writing functions. KiXtart has an EXIST function for testing if files exists. and much more...
Edited by Howard Bullock (2005-05-27 10:58 PM)
|
|
Top
|
|
|
|
#140501 - 2005-05-28 12:04 AM
Re: Split Right?
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
ACK!!!
Quote:
Command for /f "skip=1 tokens=1-2 delims=> " %i in ('quser') do @for /f "tokens=1-3 delims= " %k in ('net user %i /domain ^| find /i "home"') do @for /f %n in ('@dir %m\*.* /s /b ^| find /i "ctxfia"') do @kix32 FileDate.kix $FN="%n" $DLF="2005_05_27"
it burns!! it burns!!!!
|
|
Top
|
|
|
|
#140502 - 2005-05-31 06:19 PM
Re: Split Right?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
Sorry, about the delay in replying to this thread, had a long weekend in between.
Actually, I did read the documentation. I do that first, ever since I was chastised by Les last year for not reading the manual. (Well, actually he just pointed out something I should have done.) But, sometimes because of lack of experience or knowledge it’s difficult to visualize how to use the commands.
I also had done a search using the words FOR and COMMAND, but they are too common. The results had nothing to do with what I needed.
Could you be so kind as to point me to some examples of how I could use KiXtart to do what a FOR command would do.
|
|
Top
|
|
|
|
#140503 - 2005-05-31 09:48 PM
Re: Split Right?
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4572
Loc: USA
|
I'm a little tied up right now, but see if this will get you in the right direction. Check out WSHPipe() first.
The following example will show you, in stages, how to get the ms from a ping.
Code:
break on ;Put the output of ping into a variable(array) $output=wshpipe("ping localhost",1) ;display the output for each $line in $output ? $line next get $ ;display the output with "Reply" in it for each $line in $output if instr($line,"reply")>0 ? $line endif next get $ ;display the output with "Reply" in it and show the 5th token ;arrays in kixtart are zero based so the 5th token would actually be 4 for each $line in $output if instr($line,"reply")>0 $data=split($line," ") ? $data[4] endif next get $ ;display the output with "Reply" in it and show the 5th token but only show the actual ms for each $line in $output if instr($line,"reply")>0 $data=split($line," ") ? split($data[4],"<")[1] endif next get $ ;Finally, the same output as above, but cleaned up code for each $line in $output if instr($line,"reply")>0 ? split(split($line," ")[4],"<")[1] endif next
Function WshPipe($ShellCMD, OPTIONAL $NoEcho) Dim $oExec, $Output $oExec = CreateObject("WScript.Shell").Exec($ShellCMD) If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf $Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll If Not $NoEcho $Output Endif $WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10)) Exit($oExec.ExitCode) EndFunction
Does this help?
_________________________
(... better days ahead)
|
|
Top
|
|
|
|
#140504 - 2005-05-31 10:32 PM
Re: Split Right?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
Thanks so much Allen. It’s just that I’m a visual person and need to see it to understand it. I really appreciate it.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
|