Page 2 of 4 <1234>
Topic Options
#167787 - 2006-09-19 05:59 AM Re: Need some help
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Ok this should give you a start...

Code:

;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
$SO=SETOPTION("WrapAtEOL", "ON")
BREAK ON

Dim $ServArray, $Element, $File, $Line, $, $R, $2, $3

$ServArray = "Server1","Server2","Server3"





For Each $Element in $ServArray
    For Each $File in DirPlus($Element+"\Path","/s1 /a-d /m logfile.txt")
       
Open(1,$File)
           
$R = Readline(1)    
           
While @Error = 0
               
$2 = Split($R,"     ")
               
$3 = Split($R[1])
               
If $3[0] = "MM/DD/YYYY"
                    Open (2,"Compile.TXT",5)
                   
While @Error = 0
                   
Writeline (2,$R+@crlf)
                   
Readline(1)
                   
Next
                EndIf
                $R = Readline(1)
           
Next
        Close(1)
        Close(2)
   
Next
Next
               



;Function         DIRPlus()
;
;Author         Bryce Lindsay bryce@isorg.net
;
;Action         Returns an array containing directory files and folders
;
;Syntax         DIRPLUS("PATH","OPTIONS")
;
;Version         2.34
;
;Date Revised     2-10-05
;             2005.09.20 2.34 Filed the file/folder option "d" to be non language dependent, thanks Jochen
;
;Parameters     Path
;         Full path To To a folder that you want To Return information o
n.
;         "c:\program files"
;
;         OPTIONS
;         /S Displays files In specified directory and all subdirectories.
; Use a /S# where # is equal to the subfolder depth that you want to recurse.
;
;         /A Displays files with specified attributes.
;         attributes D Directories R Read-only files
;         H Hidden files A Files ready For archiving
;         S System files - Prefix meaning not
;
;         /M Apply mask string To filter based on InSTR(), separate Each search string witha a |
;
;         /F Return a given File extension like exe log or txt Seperate each extension type with a space
;
;
;Remarks     Finaly fixed this UDF For To handle multiple recursions,
;         also should have a faster responce time since it is using the FSO
;
;         ***Please note that the syntax For version 2.0 of this UDF has changed.***
;
;         made some tweeks using feedback from Les! thanks! Also NTDOC!
;
;Returns     Returns and array of FSO objects that are equal the file and folder objects of
;         the given path. Also returns a @ERROR code For event handling.
;
;Dependencies     FSO
;
;KiXtart Ver     4.22
;
;Example(s)     $Dir = dirplus("c:\program files") ;returns all files and folders In the "c:\program files" folder
;         $Dir = dirplus("c:\program files","/s") ;all fiels and folders including subfolders
;         $Dir = dirplus("c:\","/a-d") ;returns only a list of files In the c:\
;         $Dir = dirplus("c:\","/ad") ;returns only a list of folders In the c:\
;         $Dir = dirplus("c:\program files","/ad /s") ;returns only the folders including all subfolders.
;
;         $Dir = dirplus("g:\kix\udf","/s /ad /m dir") ; recursive subfolder search, folders only, using a mask string of "dir"
;
;         $desktop = dirplus("%userprofile%\desktop","/a-d")
;         For Each $file In $desktop
;             ? $file
;             ? $file.size
;         Next
;

Function DirPlus($path,optional $Options, optional $f, optional $sfflag)
   
If not vartype($f)     DIM $f         EndIf
    If not vartype($sfflag)     DIM $sfflag     EndIf

    DIM $file, $i, $temp, $item, $ex1, $mask,$mask1,$maskArray,$maskarray1,
   
$ex2, $code, $CodeWeight, $targetWeight, $weight, $masktrue
    DIM $tarray[0]

   
$ex1 = SetOption(Explicit,on)
   
$ex2 = SetOption(NoVarsInStrings,on)
   
$codeWeight = 0

   
If not Exist($path)
       
$temp = SetOption(Explicit,$ex1)
       
$temp = SetOption(NoVarsInStrings,$ex2)
       
Exit @ERROR
    EndIf

    If not vartype($f)
       
$f = CreateObject("Scripting.FileSystemObject").getfolder($path)
   
EndIf
    If @ERROR
        $temp = SetOption(Explicit,$ex1)
       
$temp = SetOption(NoVarsInStrings,$ex2)
       
Exit @ERROR
    EndIf

    For Each $temp In Split($options,"/")
       
$temp=Trim($temp)
       
Select
        Case left($temp,1) = "s"
            If not vartype($sfflag)
               
If Val(right($temp,-1)) = 0
                   
$sfflag = -1
               
Else
                    $sfflag = Val(right($temp,-1))
               
EndIf    
           
EndIf
        Case Left($temp,1) = "a"
            Select
            Case Right($temp,-1)="d"
                $codeWeight = $codeWeight + 1
               
$temp = "if $file.attributes & 16 " ;"if $file.type = 'File Folder' "
            Case Right($temp,-1)="-d"
                $codeWeight = $codeWeight + 1
               
$temp = "if ($file.attributes & 16)=0 " ;"if $file.type <> 'File Folder' "
            Case Right($temp,-1)="s"
                $codeWeight = $codeWeight + 1
               
$temp = "if $file.attributes & 4 "
            Case Right($temp,-1)="-s"
                $codeWeight = $codeWeight + 1
               
$temp = "if ($file.attributes & 4)=0 "
            Case Right($temp,-1)="h"
                $codeWeight = $codeWeight + 1
               
$temp = "if $file.attributes & 2 "
            Case Right($temp,-1)="-h"
                $codeWeight = $codeWeight + 1
               
$temp = "if ($file.attributes & 2)=0 "
            Case Right($temp,-1)="r"
                $codeWeight = $codeWeight + 1
               
$temp = "if $file.attributes & 1 "
            Case Right($temp,-1)="-r"
                $codeWeight = $codeWeight + 1
               
$temp = "if ($file.attributes & 1)=0 "
            Case Right($temp,-1)="a"
                $codeWeight = $codeWeight + 1
               
$temp = "if $file.attributes & 32 "
            Case Right($temp,-1)="-a"
                $codeWeight = $codeWeight + 1
               
$temp = "if ($file.attributes & 32)=0 "
            EndSelect
            $code = $temp + "$weight=$weight+1 endif" +@CRLF + $code

        Case Left($temp,1) = "m"
            $maskarray = Split(Right($temp,-2),"|")
           
$codeweight = $codeweight + 1
           
$code = "$masktrue=0 for Each $mask in $maskarray if instr($file.name,$mask) $masktrue=1 " +
           
"EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code
        Case Left($temp,1) = "f"
            $maskarray1 = Split(Right($temp,-2)," ")
           
$codeweight = $codeweight + 1
           
$code = "$masktrue=0 for Each $mask1 in $maskarray1 if substr($file.name,Instrrev($file.name,'.')+1)" +
           
"=$mask1 $masktrue=1 EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code

        EndSelect
    Next
    $code = "$weight = 0 $targetWeight = " + $codeweight + @CRLF + $code
    $code = $code + "if $weight = $targetweight Exit 1 endif"

    For Each $file In $f.subfolders
        If Execute($code)
           
$tarray[$i] = $file
            $i = $i + 1
           
ReDIM preserve $tarray[$i]
       
EndIf
        If $sfflag
            $temp = dirplus($file,$options,$file,$sfflag-1)
           
For Each $item In $temp
                $tarray[$i] = $item
                $i = $i + 1
               
ReDIM preserve $tarray[$i]
           
Next
        EndIf
    Next
    For Each $file In $f.files
        If Execute($code)
           
$tarray[$i] = $file
            $i = $i + 1

           
ReDIM preserve $tarray[$i]
       
EndIf
    Next

    If $i
        ReDIM preserve $tarray[$i-1]
       
$i=0
   
Else
        $tarray = 0
   
EndIf

    $dirplus = $tarray
    $temp = SetOption(Explicit,$ex1)
   
$temp = SetOption(NoVarsInStrings,$ex2)
   
Exit @ERROR
EndFunction




Top
#167788 - 2006-09-19 06:17 AM Re: Need some help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Tony the difficult part is we HAVE to know some EXACT marker to look for, otherwise very difficult to help you.

In your example, will EVERY logfile have the exact same word Day
followed by a TAB or will Day
possibly be elsewhere or a different name ?

I'm right in the middle of getting ready to rebuild my machine and I'm archiving off about 1/2TB so my system is a bit slow for doing much right now.

Would love to help but we do need some EXACT details otherwise the text data part will be impossible to do.

Top
#167789 - 2006-09-19 06:18 AM Re: Need some help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Well I see I'm a bit late and Garg has stepped up to the plate.

Cool, was starting too feel a bit bad for you, but didn't really have the time to help all the way either right now.

Thanks Gargoyle

Top
#167790 - 2006-09-19 09:07 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
Well, as for that part, searching it is something I will worry about later. However... to answer your question:

The "Day" field is a three letter abbreviation of the day posted in the following field, "Date". Truth be told, I can't see how it could be useful in any way, or why it would be there first. And, to specify, YES, it is ALWAYS three letters, and followed by a tab... which is good in this case: should be easier to skip programmatically.

What I need to do is generate a monthly compilation of this list (it's a bit more involved, of course). So I would need to start at one date (7/1/2006) and grab everything after that. And of course it would be complicated by the fact that the user may not have anything in the file for that day, so you would have to also check for whatever days there ARE after that date (if they were on vacation, maternity leave, etc).

However, this is intended to be run for the previous month, so it wouldn't get too far out of hand.

Thanks for the code above, I'm going to go over it and try it out right now!
_________________________
Be kind; each person is fighting his own private war.

Top
#167791 - 2006-09-19 09:25 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
Gargoyle:

I tried your script out, but since it isn't mapping a drive it did not work (I can't use UNC paths in our environment).

Now I'm assuming in $serveArray I enter "\\server\share"? Or just "server\share"?

Also, one problem with the date: it doesn not use MM/DD/YYYY... it will use M/D/YYYY if the number is a single digit.


Edited by Tony72 (2006-09-19 09:36 PM)

Top
#167792 - 2006-09-19 09:49 PM Re: Need some help
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
You can easily enough change $Servarray to = your mapped drives EX: $Servarray = "q:", "x:", "y:"

The Date portion you need to input, the MMDDYYYY was just a place holder

As to your statement that you need that date or any date thereafter complicates things a bit as it will only check for the specific date that you specify

Top
#167793 - 2006-09-19 10:05 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
Actually, how difficult would it be just to grab just a specific month/year (all 8/?/2006 and 8/??/2006)?

Just for the moment, what can I chop out to get it to take all the users, find that file (if it exists), and dump all the contents into one file?

Top
#167794 - 2006-09-19 10:08 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
For some reason I keep getting an "EndIf with no If" error on line 29. I can clearly see the If above it... wth?
Top
#167795 - 2006-09-19 10:33 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
I customized some stuff, and it seemed to be running, but finally ended stating "invalid method/function call: missing comma!" on Line 22.

Which... I think is
If $3[0] = "MM/DD/YYYY
So that doesn't make sense. I filled in the info with an actual date, but how does this handle not finding that date?

Ugh.

Top
#167796 - 2006-09-19 10:35 PM Re: Need some help
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
mismatched quote
Top
#167797 - 2006-09-19 10:39 PM Re: Need some help
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
While does not have a next but a loop so this:

Quote:


While @Error = 0
Writeline (2,$R+@crlf)
Readline(1)
Next





Should be changed to:

Quote:


While @Error = 0
Writeline (2,$R+@crlf)
Readline(1)
Loop





Look at the bold parts.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#167798 - 2006-09-19 11:09 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
I had a feeling this was going to happen. I've spent the last few hours trying to get this working, and it seems like all the trouble is caused by the problems with how the script searchs the text file.

Can anyone just give me a quick hint to what to carve out to get it to just take the entire text file and append it to a combined log file?

Top
#167799 - 2006-09-19 11:24 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
I specified having it write to "c:\temp\compile.txt", but the file is never there. A few times during testing it exited without error, but usually it keeps giving the "missing comma" error for the line with the date.

Is there a way to have it write to the file each time it opens one of the user log files?

Code:
;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
$SO=SETOPTION("WrapAtEOL", "ON")
BREAK ON
Dim $ServArray, $Element, $File, $Line, $, $R, $2, $3
$ServArray = "x:","y:"
For Each $Element in $ServArray
For Each $File in DirPlus($Element+"\location\data","/s1 /a-d /m logfile.txt")
Open(1,$File)
$R = Readline(1)
While @Error = 0
$2 = Split($R," ")
$3 = Split($R[1])
IF $3[0] = "8/1/2006"
Open (2,"c:\temp\Compile.TXT",5)
While @Error = 0
Writeline (2,$R+@crlf)
Readline(1)
Loop
EndIf
$R = Readline(1)

Close(1)
Close(2)
Next
Next

;Function
EndFunction

_________________________
Be kind; each person is fighting his own private war.

Top
#167800 - 2006-09-19 11:29 PM Re: Need some help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Well here is a condensed version (currently does not work properly but close).
Perhaps Jooel or Mart or someone else has the time to help you complete it.

The issue is in how the Open/Read/Write works - it finds
the data, but then writes multiple times which it
shouldn't do - just don't have time to further debug it.



Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $Path, $File, $Folder, $Folders, $FileData
Dim $Date, $Nul, $R, $2, $3
$Date = '1/1/2006'
$File = 'logfile.txt'
$Path = 'C:\Office\Type'
$Folders = DirL($Path)
For Each $Folder In $Folders
If $Folder
$Nul = Open(1,$Path+'\'+$Folder+'\'+$File)
$R = Readline(1)
While @Error = 0
$2 = Split($R,CHR(9))
If InStr($2[1],$Date)
$Nul = Open(2,'C:\TEMP\Compile.TXT',5)
While @Error = 0
$Nul = Writeline(2,$R+@crlf)
$R Readline(1)
Loop
EndIf
$R = Readline(1)
Loop
Close(1)
Close(2)
EndIf
Next

Function DirL($f)
Dim $a[0]
$f = Dir($f)
While Not @ERROR
If $f <> '..' And $f <> '.'
$a[UBound($a)] = $f
ReDim Preserve $a[UBound($a)+1]
EndIf
$f = Dir()
Loop
If UBound($a)
ReDim Preserve $a[UBound($a)-1]
Else
$a = 0
EndIf
$DirL = $a
EndFunction

Top
#167801 - 2006-09-19 11:33 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
Ok, I removed the
IF $3[0] = "8/1/2006"
and the "EndIf".

I'm crossing my fingers, hoping it will just make a dump of the whole file.

Top
#167802 - 2006-09-19 11:37 PM Re: Need some help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Well you need to decide what you want. Do you want the entire file or just the line with the date you specified?
Top
#167803 - 2006-09-19 11:39 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
My above comment was about Gargoyle's script.

NTDOC, or someone else: is it easier if the script doesn't even care about the date, and just takes the all the log files and dumps their contents into one file?

Top
#167804 - 2006-09-19 11:43 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
No, I never needed just one line: I was looking to start at the date and get that point and everything after it (or, specificly, to get an entire month- we would run it at the start of each month).

I mentioned before, I would be more than happy just to have everything put together so I can sort it with Excel by hand. Since there are hundreds of users, it will be far easier to sort by hand and erase what I don't need. Other wise, I have to go to each folder, open the file, copy, paste, open the next user, etc.

Top
#167805 - 2006-09-20 12:01 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
Damn, I was happy, it ran, but my elation was premature. It seemed to have written the info on the date specified about 20 times or whatever (I thought it completed the job, but when I went to sort the data I noticed).
_________________________
Be kind; each person is fighting his own private war.

Top
#167806 - 2006-09-20 12:09 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
How can I make it start at line 1 and go to the end? For Next?
Top
Page 2 of 4 <1234>


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

Who's Online
0 registered and 809 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.071 seconds in which 0.028 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