Tony72
(Getting the hang of it)
2006-09-15 10:01 PM
Need some help

Ok, I was assigned a long boring task, and thought "this looks like a job for KiXtart". However, I've only done logon scripting, registry editting, and file movement with it. Reading and manipulating text is not something I'm too familiar with.

Ok, here is what I need to do, and I'll follow with what I want to do (I have to get the "need" done, since this project needs to be completed).

Each user has a file in their home directory. So I need a script to go in their directory, open a file, search for a date, then copy from that location all the way to the end, and paste it (append) into a text file for me to look through. There are a few hundred users, so doing it by hand will take a loooong time.

Now what I would 'like' to do is have kixtart build the user list itself, then search those drives, and grab all the info after a date specified via user input.

Can anyone help me out here?


Gargoyle
(MM club member)
2006-09-15 10:19 PM
Re: Need some help

Does the input file (the one you need to read from) have a structured layout?

Assuming it does, then you could
Code:

Open(1,"YourFileHere.TXT",2"

Do $ = Split(Readline(1)," ") Until $[0] = "InsertDateHere"
Open (2,"YourOtherFile.TXT",5)
While @Error = 0
Writeline (2,$R+@crlf)
$R = Readline(1)
Next
Close(1)
Close(2)



May not be perfect code, but should give you an idea


Tony72
(Getting the hang of it)
2006-09-15 11:15 PM
Re: Need some help

Yes, the first entry of every line is the date (and I believe each entry is separated by a tab). The only thing I dislike about it is how it uses single digits (rather than 01/01/2006 it puts 1/1/2006, so sorting it in a spreadsheet app can get it mixed up). But anyway, I would just use a straight match, like "7/1/2006", and grab everything past that point.

Tony72
(Getting the hang of it)
2006-09-15 11:19 PM
Re: Need some help

Would the script you wrote copy everything until the end of the file?

Witto
(MM club member)
2006-09-15 11:50 PM
Re: Need some help

Quote:


kixtart build the user list itself




Maybe this code is usefull and can be converted to KiX
Look for "Enumerate all users in domain"
CreateUserList2


Gargoyle
(MM club member)
2006-09-16 12:06 AM
Re: Need some help

without fully testing I will give you a conditional yes

Tony72
(Getting the hang of it)
2006-09-16 12:21 AM
Re: Need some help

No, that won't help. There are several offices in the domain, and I only want to grab users who are here. Also, there is more than one server with user home directories.

The best way I figured to do this is a batch file which will map a drive to one server, create a list of all the folders in the user directory, then do the same for the other servers. That's good enough, but the problem is having it take that list and turn it into something I can use.

I can make the data array manually, but how would I create a dynamic one?

Quote:

Quote:


kixtart build the user list itself




Maybe this code is usefull and can be converted to KiX
Look for "Enumerate all users in domain"
CreateUserList2




Bryce
(KiX Supporter)
2006-09-16 12:25 AM
Re: Need some help

these user drives, are they just folders in a share? if use, use something like dirplus to crawl all fo the files that you are looking for.

Code:
$files = dirplus("\\server\share",'/s1 /a-d /m datafile')



that will return a file handle to each file 1 lvl deep, so the root of each users folder in the \\server\share. and only the files that have the name "datafile" in them.

that should handle the file part...


Tony72
(Getting the hang of it)
2006-09-16 12:25 AM
Re: Need some help

So I guess I should have clarified: I don't actually have trouble creating the user list (well, having KiXtart doing it rather than dos would be cleaner), my problem is having it dynamically create a data array to be used inside the script.

Gargoyle
(MM club member)
2006-09-16 12:27 AM
Re: Need some help

If all of your directories are indeed under \users\ then you can use one of many different DIR UDF's found at http://www.kixtart.org/udf

Tony72
(Getting the hang of it)
2006-09-16 12:30 AM
Re: Need some help

Well... kind of. The way the network security works, I can't use UNC paths, so I have to map network drives.

But at that point, the folders would pretty much be X:\Office\Type\{username}
Then all the users are inside that particular folder (so the only difference is the server and volume, which is irrelevant once the drive is mapped).


Tony72
(Getting the hang of it)
2006-09-16 12:32 AM
Re: Need some help

Well I guess that's the problem, I need to know what different things I'm stringing together. I've never had KiXtart read files, so I'm out of my element. Also, I haven't used it in about four years, so my brain is all rusty overall

Quote:

If all of your directories are indeed under \users\ then you can use one of many different DIR UDF's found at http://www.kixtart.org/udf




Gargoyle
(MM club member)
2006-09-16 12:36 AM
Re: Need some help

As Bryce mentioned you can use DIRPlus() to create your array, it can be found at the link I provided.

In your script you would then run the DIRPlus UDF to create your array of user folders,

Then with that you can use the code that I provided and do a For Each $ in $Array to read the files


Tony72
(Getting the hang of it)
2006-09-16 12:37 AM
Re: Need some help

Here is an overview of what I would like:

1. create list of folders in user directory

2. open user directory, and read "logfile.txt"

3. search logfile for a specific date, copy that point and everything to the end

4. paste that information into "userlogs.txt"

5. goto #2 until the end of the list.

Then I will have a complete compilation of all the user's log files, starting at a certain date.


Tony72
(Getting the hang of it)
2006-09-16 12:47 AM
Re: Need some help

Cool, I'm testing it out. I'm hoping to have this done by monday (boss is waiting for the info).

Bryce
(KiX Supporter)
2006-09-16 12:47 AM
Re: Need some help

my advice, dont beat your head in trying to reinvent the wheel... :P several UDF's out there to do the heavy lifting for you.

Code:

for each $file in dirplus('X:\Office\Type','/s1 /a-d /m logfile.txt')
? $file.path + $file.name

$filedata = loadfile($file.path+$file.name)

/* at this point, i dont knwo wht your data looks like,
but the variable $filedata should be the entire contents of logfile.txt
that was found in one of the users folders.

This code uses 2 UDF's Dirplus() and Loadfile() */


next



Tony72
(Getting the hang of it)
2006-09-16 12:47 AM
Re: Need some help

BTW, thanks for all the help everyone!

Tony72
(Getting the hang of it)
2006-09-19 01:03 AM
Re: Need some help

Ok, I've really been bummed out by this over the weekend. My skillz are gone, I can't seem to get anything working or even understand what I'm doing now.

If someone can suggest to my burned-out brain how to string this together, I'll name my firstborn kid after you (pending spousal approval, so take it how you will).


NTDOCAdministrator
(KiX Master)
2006-09-19 02:02 AM
Re: Need some help

Can you please post an example of the LOG file so that we can see exactly what it is you're trying to copy, gather.

Thanks.


Tony72
(Getting the hang of it)
2006-09-19 04:08 AM
Re: Need some help

Sure. Actually, however, just to get this working I'm willing to be satisfied with taking the entire file, append them all into one file, and not worry about searching it.
(quote marks added for clarity)
"Day" "1/1/2006 5:55:55 PM" "username" "Server" "Computername" "IrrelevantData#1" "IrrelevantData#2"

I don't know if the format comes through, but it's all separated by tabs.

Here is what I would be happy with for right now, just so I can get this thing going:

there are multiple shares to connect to

\\Server1\share
\\Server2\share
\\Server3\share

They have the same dir structure once a drive is mapped

Location\data\{username}

So I would like it to connect to the the first server, dir the data directory, then go inside each username directory. Open logfile.txt, and append it to one text file, then move on to the next folder until it runs out of user folders.

At at that point, it will connect to the next server, and do the same thing. Then, finally, connect to the last server.

Once that is done, I'll just work with the data in Excel and worry about sorting it for later.

Sorry if I sound frantic, but I'm getting lots of pressure on this. I started just doing it by hand... but there are freaking hundreds of users, it's going to take half of forever!


Gargoyle
(MM club member)
2006-09-19 05:59 AM
Re: Need some help

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





NTDOCAdministrator
(KiX Master)
2006-09-19 06:17 AM
Re: Need some help

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.


NTDOCAdministrator
(KiX Master)
2006-09-19 06:18 AM
Re: Need some help

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


Tony72
(Getting the hang of it)
2006-09-19 09:07 PM
Re: Need some help

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!


Tony72
(Getting the hang of it)
2006-09-19 09:25 PM
Re: Need some help

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.


Gargoyle
(MM club member)
2006-09-19 09:49 PM
Re: Need some help

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


Tony72
(Getting the hang of it)
2006-09-19 10:05 PM
Re: Need some help

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?


Tony72
(Getting the hang of it)
2006-09-19 10:08 PM
Re: Need some help

For some reason I keep getting an "EndIf with no If" error on line 29. I can clearly see the If above it... wth?

Tony72
(Getting the hang of it)
2006-09-19 10:33 PM
Re: Need some help

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.


Les
(KiX Master)
2006-09-19 10:35 PM
Re: Need some help

mismatched quote

Mart
(KiX Supporter)
2006-09-19 10:39 PM
Re: Need some help

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.


Tony72
(Getting the hang of it)
2006-09-19 11:09 PM
Re: Need some help

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?


Tony72
(Getting the hang of it)
2006-09-19 11:24 PM
Re: Need some help

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



NTDOCAdministrator
(KiX Master)
2006-09-19 11:29 PM
Re: Need some help

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


Tony72
(Getting the hang of it)
2006-09-19 11:33 PM
Re: Need some help

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.


NTDOCAdministrator
(KiX Master)
2006-09-19 11:37 PM
Re: Need some help

Well you need to decide what you want. Do you want the entire file or just the line with the date you specified?

Tony72
(Getting the hang of it)
2006-09-19 11:39 PM
Re: Need some help

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?


Tony72
(Getting the hang of it)
2006-09-19 11:43 PM
Re: Need some help

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.


Tony72
(Getting the hang of it)
2006-09-20 12:01 AM
Re: Need some help

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).

Tony72
(Getting the hang of it)
2006-09-20 12:09 AM
Re: Need some help

How can I make it start at line 1 and go to the end? For Next?

Gargoyle
(MM club member)
2006-09-20 01:15 AM
Re: Need some help

Change this
Code:

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


To this
Code:

$Nul = Open(2,'C:\TEMP\Compile.TXT',5)
While @Error = 0
$Nul = Writeline(2,$R+@crlf)
$R Readline(1)
Next
Code:




Les
(KiX Master)
2006-09-20 01:18 AM
Re: Need some help

While - Loop, not Next

Witto
(MM club member)
2006-09-20 01:37 AM
Re: Need some help

Code:

$R=Readline(1)



Gargoyle
(MM club member)
2006-09-20 01:50 AM
Re: Need some help

Cut and paste - My bad

Tony72
(Getting the hang of it)
2006-09-20 02:27 AM
Re: Need some help

Gargoyle:

I've never gotten your script to run. It sits there for about 15 minutes, then usually errors out, and never even creates an output text file (this last time I got a "undefined variable [Nul]!" error.

I'm assuming it ran out of log files... but it has never generated any output text file. Does it have to finish running before it will write an output file?


Gargoyle
(MM club member)
2006-09-20 03:05 AM
Re: Need some help

It should create the file right off.

You may want to run it in debug mode so that you can see exactly where it is having an issue.

As for the $Nul, that is because it was added after the fact, and it is not Dimmed, and the explicit option is turned on.


Tony72
(Getting the hang of it)
2006-09-20 04:00 AM
Re: Need some help

Actually, the one NTDoc has above I managed to get working after inserting a few pieces of site-specific info: it goes into each user's directory and the text file gets written.

Could someone just recommend what to change in that one so it will either take all the entries for a specified month, or else just grab everything? Which ever is fastest and easiest at this point: the people waiting on this are getting very impatient that it's not done.

My problem, I know, but aaaaaaaaaargh. It sucks knowing I once knew how to do this, and can't remember at all. I must have lost several points of int somewhere... and didn't have any to spare in the first place.


Gargoyle
(MM club member)
2006-09-20 04:48 AM
Re: Need some help

You can alway's just take the output from DirPlus and concanate the files into one.

Copy $File1+$File2+$File3 OutputFile.txt


Tony72
(Getting the hang of it)
2006-09-20 11:46 PM
Re: Need some help

Is there any way to handle it like a DOS
Code:

type logfile.txt>>c:\temp\compile



For some reason I remember the DOS stuff, but KiXtart has faded away


Tony72
(Getting the hang of it)
2006-09-20 11:49 PM
Re: Need some help

Wow... did I just answer my own question?

I'll test it out... I might be able to do a
Code:
SHELL "CMD.EXE type logfile.txt>>C:\temp\compile.txt"



Wish me luck.


Tony72
(Getting the hang of it)
2006-09-21 01:52 AM
Re: Need some help

Damn, it isnt working. For some reason, it will type the log file, but it isnt piping it into compile.txt

Gargoyle
(MM club member)
2006-09-21 02:15 AM
Re: Need some help

Code:

for each $file in dirplus('X:\Office\Type','/s1 /a-d /m logfile.txt')
Shell "Copy c:\temp\compile.txt + " + $File " c:\temp\compile.txt"
next



This is untested, but may do the job of concatanting all the files together.


Tony72
(Getting the hang of it)
2006-09-21 02:44 AM
Re: Need some help

Is this for your script or NTDOC's? Where would I insert this (and what would I replace)?

NTDOCAdministrator
(KiX Master)
2006-09-21 02:52 AM
Re: Need some help

Tony,

Okay, so lets copy all the files into a single file.
Are you sure that's what you want?
I don't see how you're going to know who's data is whos that way.

I'll make a code change that will work just fine and post it in a minute, but really think that is not going to work for you.

What version of KiXtart did you say you're using?


Les
(KiX Master)
2006-09-21 03:10 AM
Re: Need some help

SHELL "%comspec% /c type logfile.txt >>C:\temp\compile.txt"

NTDOCAdministrator
(KiX Master)
2006-09-21 03:16 AM
Re: Need some help

Okay here you go. This will copy all the logfile.txt files into a single file (you need to modify your locations, etc..)

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

Dim $Path, $Dest, $File, $Files, $Folder, $Folders
$Path = 'C:\Office\Type'
$File = 'logfile.txt'
$Dest = 'C:\TEMP\AllUserLogFiles.txt'
If Exist($Dest)
Del $Dest
EndIf
$Folders = DirL($Path)
For Each $Folder In $Folders
If $Folder
If Exist($Path+'\'+$Folder+'\'+$File)
$Files = $Files + '+' + $Path+'\'+$Folder+'\'+$File
EndIf
EndIf
Next
SHELL '%Comspec% /c COPY ' + Right($Files,-1) + ' ' + $Dest + ' >nul 2>nul '
'File copy status: ' + @ERROR + ' - ' + @SERROR ?


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


NTDOCAdministrator
(KiX Master)
2006-09-21 03:18 AM
Re: Need some help

Hmmm just thinking of this method though. If you had hundreds of files it would not work as the command line would be too long.

Though slow I think you may have to do the redirect of each file into a single file.


Tony72
(Getting the hang of it)
2006-09-21 03:20 AM
Re: Need some help

I'm using the 2010.452.

Having it all in one file is fine: I'll just sort it with Excel. If I sort everything by the date column, I can remove everything not in the month I want. Then I remove certain other details, and I'm done.


NTDOCAdministrator
(KiX Master)
2006-09-21 03:22 AM
Re: Need some help

Okay, this method should work regardless
of the amount of files you need to process.

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

Dim $Path, $Dest, $File, $Files, $Folder, $Folders
$Path = 'C:\Office\Type'
$File = 'logfile.txt'
$Dest = 'C:\TEMP\AllUserLogFiles.txt'
If Exist($Dest)
Del $Dest
EndIf
$Folders = DirL($Path)
For Each $Folder In $Folders
If $Folder
If Exist($Path+'\'+$Folder+'\'+$File)
SHELL '%comspec% /c type ' + $Path+'\'+$Folder+'\'+$File + ' >>'+$Dest
EndIf
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


Tony72
(Getting the hang of it)
2006-09-21 03:22 AM
Re: Need some help

Is there any way to have it do my suggestion from before, just have it use DOS and do a "type logfile.txt>>compile.txt"?

I tried it myself, but I wasn't sure if I was screwing something up.


Les
(KiX Master)
2006-09-21 03:23 AM
Re: Need some help

You missed the /c

Tony72
(Getting the hang of it)
2006-09-21 03:23 AM
Re: Need some help

ah ok, cool.

I'll try it out right now! Thanks again to everyone!


NTDOCAdministrator
(KiX Master)
2006-09-21 03:23 AM
Re: Need some help

The above code I just posted does that.

Tony72
(Getting the hang of it)
2006-09-21 03:26 AM
Re: Need some help

Ah I see.

Tony72
(Getting the hang of it)
2006-09-21 03:33 AM
Re: Need some help

w00t!!!

It worked!!

Thanks a ton. I'll probably revisit this some time to figure out a way to have it sort the file, but for now this is perfect!!

My firstborn will be named NTDoc. Hope he doesn't get picked on in school =)


NTDOCAdministrator
(KiX Master)
2006-09-21 03:43 AM
Re: Need some help

You're welcome.

Like said. You can get just the specific data you want, but you have to ver VERY specific on the format and details.

Otherwise one wastes time trying to accomodate unknown data.


Tony72
(Getting the hang of it)
2006-09-21 04:02 AM
Re: Need some help

Yeah, I have a few ideas about getting it, but I'll wait til later (since I'm looking for just the month, it only needs to look at the first two characters in the date, and get rid of the "\" if it uses a single digit. The file always has a three letter day, followed by a tab, followed by the date).

I just finished removing all the stuff I didn't need by sorting with Excel. It needs to have more stuff taken out (we are looking for a specific pattern), but this is the big piece everyone was waiting on.

Woohoo!!