Sign in to follow this  
Followers 0
Irish1986

Read multiple files to a CSV - Noobs need help

3 posts in this topic

Hi all,

I am new to AutoIt. I have been trying in the last couple of weeks to create a rather simple tool to help me in my daily task.

I have lots of issue understanding how to code works but here what I am trying to achieve. If a few people would be kind enough to redirected me toward good documentation or help me with my code I would be very happy.

My utility needs to achieve the following:

1- Open an read data from 100 to 200 individual ASCII files all located in the same directory

2- Extract line specific information base marker inside the ASCII file (the length of the file change but not the marker)

3- Compile some data and output this in a CSV file for later use in Excel

Here an exemple of what I am trying to capture.

The markers are #LICENSE, #GENERAL, etc... (all with # sign) and I desire to capture lines likes DATE :, PRG. NAME :, MATERIAL :, SHEET USAGE EFFICIANCY (RECTANGULAR) :, etc...

; FMS REPORT FILE
; SOFTWARE v16.18.10 : P10-80011801-006015
;
#LICENSE
VERSION : 16.18.10
SERIAL : P10-80011801-006015
COMPUTER NAME : HOME PC
SYSTEM NAME : HOME PC
#GENERAL
DATE : Fri Dec 03 17:26:46 2010
UNITS : INCHES
PRG. NAME : A1-000265
PRG. NO. : NOT USED
NESTING NAME : A1-000265
DOS FILE NAME : \\HOME PC\A1-000265.JNF
NC FILE NAME : \\HOME PC\A1-000265.NC
MACHINE : LECTRA FX72 (pp 60500)
MATERIAL : N331-9026
THICKNESS : 0.005
SHEET SIZE X : 46.375
SHEET SIZE Y : 50.04
PLATE NAME : "309200568-0001A"
ROLL INIT X : 1200.0
ROLL INIT Y : 50.04
PLATE COST : 0.00
#TIMES
SHEET USAGE EFFICIANCY (RECTANGULAR) : 13.9%
SHEET USAGE EFFICIANCY (ACTUAL) : 6.2%
TOTAL DISTANCE TRAVELLED : 170.1665
TOTAL PROFILE CUTTING DISTANCE : 96.9065

Share this post


Link to post
Share on other sites



Well part of my problem is that I don't know where to start.

I have found several exemple that I was able to configure and make it kind of like this but it isn't very useful and it rely on a batch script. Also I would like to add a GUI but not until I fix the code therefore I really want to get this to works.

; Does recursive search
 ;COMMAND LINE:  .EXE "Search directory" "Filetype" "Search String"
 ;
 ;example1
 ;list only GR files:
 ;NewFilesearch.exe "C:\WINJC\GEO" ".GR" "NONE"
 ;
 ;example
 ;find
#include <File.au3>

$SCRIPTDIR= @ScriptDir

$SEARCHDIR0 = $CmdLine[1]

IF Stringright($SEARCHDIR0,1) = "\" Then
    $Searchdircount = number(StringLen($SEARCHDIR0) - 1)
    $SEARCHDIR = Stringleft($SEARCHDIR0,$Searchdircount)
Else
    $SEARCHDIR = $SEARCHDIR0
EndIf
$SEARCHFILETYPE= "FMS"
$LOGFILE = $SCRIPTDIR & "\ "& $SEARCHFILETYPE & "log.csv"
    $a = _FileSearch($SEARCHDIR & "\" & "*." & $SEARCHFILETYPE, 1)
        FileOpen($LOGFILE,10)
$COUNT = 0
    ;FileWriteLine ($LOGFILE, "Total Files Found:  " & $a[0])
    If $a[0] > 0 Then
        ; all files
        For $i = 1 To $a[0]
            $B = StringSplit($a[$i],"\")
            $C = $B[$B[0]]
            $D = StringTrimRight($C,3)
            $GRFILE = $D
            $JGFFILE = $D
            $Contents = FileRead($a[$i])
            $RevisionExists = StringInStr($contents,"COMPONENT REVISION :")
            $MATERIAL0 = FileReadLine($a[$i],6)
            $MATERIAL = StringTrimLeft($MATERIAL0,11)
            $THICKNESS0 = FileReadLine($a[$i],7)
            $THICKNESS = StringTrimLeft($THICKNESS0,12)
            FileWriteLine ($LOGFILE,'"' & $JGFFILE & '"' &  "," & $MATERIAL & ","  & $THICKNESS &  "," & '"' & $a[$i]& '"')
                        $COUNT = $COUNT +1
        Next
    EndIf
        FileClose ($LOGFILE)
;--------------------------------------------
;
; search
Func _FileSearch($szMask, $nOption)
    $szRoot = ""
    $hFile = 0
    $szBuffer = ""
    $szReturn = ""
    $szPathList = "*"
    Dim $aNULL[1]

    If Not StringInStr($szMask, "\") Then
        $szRoot = @ScriptDir & "\"
    Else
        While StringInStr($szMask, "\")
            $szRoot = $szRoot & StringLeft($szMask, StringInStr($szMask, "\"))
            $szMask = StringTrimLeft($szMask, StringInStr($szMask, "\"))
        WEnd
    EndIf
    If $nOption = 0 Then
        _FileSearchUtil($szRoot, $szMask, $szReturn)
    Else
        While 1
            $hFile = FileFindFirstFile($szRoot & "*.*")
            If $hFile >= 0 Then
                $szBuffer = FileFindNextFile($hFile)
                While Not @error
                    If $szBuffer <> "." And $szBuffer <> ".." And _
                            StringInStr(FileGetAttrib($szRoot & $szBuffer), "D") Then _
                            $szPathList = $szPathList & $szRoot & $szBuffer & "*"
                    $szBuffer = FileFindNextFile($hFile)
                WEnd
                FileClose($hFile)
            EndIf
            _FileSearchUtil($szRoot, $szMask, $szReturn)
            If $szPathList == "*" Then ExitLoop
            $szPathList = StringTrimLeft($szPathList, 1)
            $szRoot = StringLeft($szPathList, StringInStr($szPathList, "*") - 1) & "\"
            $szPathList = StringTrimLeft($szPathList, StringInStr($szPathList, "*") - 1)
        WEnd
    EndIf
    If $szReturn = "" Then
        $aNULL[0] = 0
        Return $aNULL
    Else
        Return StringSplit(StringTrimRight($szReturn, 1), "*")
    EndIf
EndFunc   ;==>_FileSearch

Func _FileSearchUtil(ByRef $ROOT, ByRef $MASK, ByRef $RETURN)
    $hFile = FileFindFirstFile($ROOT & $MASK)
    If $hFile >= 0 Then
        $szBuffer = FileFindNextFile($hFile)
        While Not @error
            If $szBuffer <> "." And $szBuffer <> ".." Then _
                    $RETURN = $RETURN & $ROOT & $szBuffer & "*"
            $szBuffer = FileFindNextFile($hFile)
        WEnd
        FileClose($hFile)
    EndIf
EndFunc   ;==>_FileSearchUtil

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0