Sign in to follow this  
Followers 0
cmilanelo

A lot of work...

5 posts in this topic

Hello People!

I need to do a work for automatize a process, but I just don't have the knowing necessary to do this. I've been posted some questions in the forun, but it's not enough for me to do the work myself.

So, that's what I need the script do:

1) Head a folder (a fixed folder) and show me a array with all the .txt files inside it (I'm sending a sample file in attachment "SAMPLE.txt")

2) The script needs to identify which the maximums and minimums numbers in the columns 6, 7 and 8 (but don't need to show me yet, just save it in variables). The user Malkey did a good code for it:

#include <Array.au3>
#include <File.au3>

; Data from http://www.autoitscript.com/forum/index.php?showtopic=112577&view=findpost&p=789740
; put in file "Test1.txt" in script directory.
Local $sFileIn = "C:\....\SAMPLE.txt"

Local $aMaxMin[3][4] = [[" ", "Col6", "Col7", "Col8"],["Max"],["Min"]]
Local $aTemp

For $j = 1 To 3
    $aTemp = _StringColumnMaxMin($sFileIn, $j + 5)
    $aMaxMin[1][$j] = $aTemp[0]
    $aMaxMin[2][$j] = $aTemp[1]
Next

_ArrayDisplay($aMaxMin)


; Returns an array. array[0] contains Maximum; array[1] contains Minimum
Func _StringColumnMaxMin($sFileIn, $col = 1)
    Local $aArray, $sStr, $iMaxMin[2], $sLine, $aFile, $sDataInModified
    _FileReadToArray($sFileIn, $aFile)

    For $i = 1 To $aFile[0]
        StringRegExpReplace($aFile[$i], "(?:[^ ]+?)(\h+?)", "")
        If @extended > 8 Then $sDataInModified &= $aFile[$i] & @CRLF; Check number of "word-spaces" occurrences on each line.
    Next

    $sStr = StringRegExpReplace($sDataInModified & @CRLF, "(?:\h*?)(?:[^ ]+\h+?){" & $col - 1 & "}([0-9\-.,]+)(?:\h*.*)\v+|\z", "\1" & @CRLF)
    $aArray = StringSplit(StringStripWS($sStr, 2), @CRLF, 3)
    $iMaxMin[0] = $aArray[0] ;Max
    $iMaxMin[1] = $aArray[0] ;Min

    ; Numeric comparsion without thousand comma to find max and min values in array, $aArray.
    For $i = 1 To UBound($aArray) - 1
        If (Number(StringReplace($aArray[$i], ",", "")) > Number(StringReplace($iMaxMin[0], ",", ""))) Then _
                $iMaxMin[0] = $aArray[$i] ; Max
        If (Number(StringReplace($aArray[$i], ",", "")) < Number(StringReplace($iMaxMin[1], ",", ""))) Then _
                $iMaxMin[1] = $aArray[$i] ; Min
    Next

    
    
    Return $iMaxMin
EndFunc ;==>_StringColumnMaxMin

2.1)In fact, the saved numbers must be encreased in 2 units (in the positive cases) e decreased in 2 units (in the negative cases). In all files, I'll have 3 positive numbers and 3 negative numbers.

3) After read the files, identify the max and min of the 3 columns, and encrease (and decrease) 2 units in each number identified, the script have to generate another .txt file with the same name of the file that the original, but with a "_" before (ex.: the file read is 123.txt, the file generated must be _123.txt).

3.1) This new file will contain the max and min numbers already encreased (I'm sending a file created based in the first file I have sent: "_SAMPLE.txt")

3.2) As we can see in that new file, the columns 6,7 and 8 contains the numbers of the corresponding column in the another file, like I will show:

[col6]    [col7]    [col8]
 min       min       min
 max       min       min
 min       max       min
 max       max       min
 min       min       max
 max       min       max 
 min       max       max
 max       max       max

And here we have the biggest problem, because in this file, the spaces between the columns need to be the same in all the files generated. So, if I open a lot of files of this, all the columns need to be exactly in the same local, changing only the numbers.

I don't know if I could be clear as to what I need. Any problems, just ask me I'll be clearer.

MUCH thanks in advance for all!

SAMPLE.txt

_SAMPLE.txt

Share this post


Link to post
Share on other sites




Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites

1) Head a folder (a fixed folder) and show me a array with all the .txt files inside it (I'm sending a sample file in attachment "SAMPLE.txt")

_FileListToArray()

Share this post


Link to post
Share on other sites

_FileListToArray()

In fact, I know how to do some steps, but I don't know how to do all of them together and, mainly, the last step, to generate the new file in that form.

Share this post


Link to post
Share on other sites

In fact, I know how to do some steps, but I don't know how to do all of them together and, mainly, the last step, to generate the new file in that form.

re: keeping the columns the same size,

I'm assuming that your numbers will never have more than a certain number of digits in them: all of your examples were no bigger than, e.g., -13.807.

Try building a string from the array returned by _StringColumnMaxMin. As you build the array, keep incrementing a variable for the current position, and when you're finished with the data that will go into one column, add enough spaces to get you to the next column starting position. Maybe keep an array of column sizes and check your string against that.

re: creating the file,

You will find the following functions useful:

FileWrite()

_FileWriteFromArray()

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