Page 1 of 1 1
Topic Options
#140487 - 2005-05-27 07:08 PM Split Right?
operez Offline
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 Offline
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 Offline
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 Offline
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 Offline
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 Offline
Fresh Scripter

Registered: 2005-04-01
Posts: 23
Could you split by "_" and then concatenate $sArray[2], $sArray[3], and $sArray[4]?
Top
#140493 - 2005-05-27 07:35 PM Re: Split Right?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Have not really looked at or tried your code but try doubling the @ sign to be @@ and see if it works.
Top
#140494 - 2005-05-27 07:47 PM Re: Split Right?
operez Offline
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 Offline
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 Offline
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
#140497 - 2005-05-27 10:22 PM Re: Split Right?
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
I'm impressed with your "for" command... not just anyone can put one together like that

Prior to my christening with kixtart, I used nothing but CMD scripts, and your script brings back some looping/goto nightmares (twich, twich) . Dump the cmd scripts and adopt Kix for everything. You won't be sorry.
_________________________
(... better days ahead)

Top
#140498 - 2005-05-27 10:45 PM Re: Split Right?
operez Offline
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 Offline
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)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#140500 - 2005-05-27 11:33 PM Re: Split Right?
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Funny you say that... I said something similar in a post way back when I first started using Kix. I can tell you that not only have I completely stopped using the "for" loops/cmd scripts, I'm amazed at how I ever even used them to begin with. They are hard to trouble shoot, have little to no structure, and try explaining it to someone who's never used it before...

The Pipe UDFs will get your output into a variable, which you can then split the data just as you did with the "Delims", creating an array. Each "token" (value) in the Array is accessable either by a for/next loop, or directly by $array[#] where # is the token you are looking for.
_________________________
(... better days ahead)

Top
#140501 - 2005-05-28 12:04 AM Re: Split Right?
Bryce Offline
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 Offline
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 Administrator Offline
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 Offline
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
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 (Glenn Barnas) and 955 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.059 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

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