Jump to content

Recommended Posts

Posted

Howdy peeps.

I have a couple of Autoit scripts with arrays in them. They have the output file (Hardcoded) into them. I really would like to be prompted where to save the files, and give it a file name. I have a "FileWriteLine" (see second code snip) setup. Though it prompts me to save every line from the array. How do I get just one file save?

Thanx for any input into this matter.

#include <Array.au3>
#include <file.au3>

Dim $FileArray, $BigArray[1][3], $MidArray, $temp
; $FileArray = _FileListToArray("F:\nicole-here\052")
$fold = FileSelectFolder("Choose a folder.", "")
; $FileArray = _FileListToArray("$fold")
$FileArray =_FileListToArray($fold,"*",1)

ReDim $BigArray[$FileArray[0]][3]                   ;will hold all the file names split by "-"
Dim $MidArray[$FileArray[0]]                    ;will hold the mid number (FC)
For $i = 1 To $FileArray[0]
    $temp = StringSplit($FileArray[$i], "-")
    For $j = 1 To $temp[0]
        $BigArray[$i-1][$j-1] = $temp[$j]               ;put the value in the big array
        If $j = 2 Then $MidArray[$i-1] = $temp[$j]  ;put middle string in $MidArray
    Next
Next
;_ArrayDisplay($BigArray, "Big")
;_ArrayDisplay($MidArray, "Mid")
Dim $UniqueArray, $tempArray, $ResultArray
$UniqueArray = _ArrayUnique($MidArray)              ;get unique mid-strings
;_ArrayDisplay($UniqueArray, "Unique")
For $i = 1 To UBound($UniqueArray)-1
    $tempArray = _ArrayFindAll($BigArray, $UniqueArray[$i], 0, 0, 0, 0, 1)  ;get all array indexes for the same mid-string
    ;_ArrayDisplay($tempArray, "Find"&$UniqueArray[$i])
    Dim $ResultArray[UBound($tempArray)][3]
    For $j = 0 To UBound($tempArray) - 1            ;build a temporary array to hold these entries
        $ResultArray[$j][0] = $BigArray[$tempArray[$j]][0]
        $ResultArray[$j][1] = $BigArray[$tempArray[$j]][1]
        $ResultArray[$j][2] = $BigArray[$tempArray[$j]][2]
    Next
    _ArraySort($ResultArray, 0, 0, 0, 2)
    For $k = Number($ResultArray[0][2]) To Number($ResultArray[UBound($ResultArray)-1][2])
        If _ArraySearch($ResultArray, $k, 0, 0, 0, 0, 1, 2) <> -1 Then
            ContinueLoop
        Else
            ; MsgBox(0, "Missing File", $ResultArray[0][0]&"-"&$ResultArray[0][1]&"-"&StringFormat("%03d", $k))
            ; $file = FileOpen("f:\file.txt", 1)
             ; $save = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Jpg (*.jpg)", 18) & ".jpg"
              $save = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Txt (*.txt)")
             FileWriteLine($save, $ResultArray[0][0]&"-"&$ResultArray[0][1]&"-"&StringFormat("%03d", $k))
               
        EndIf
    Next
Next

$save = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Txt (*.txt)")
             FileWriteLine($save, $ResultArray[0][0]&"-"&$ResultArray[0][1]&"-"&StringFormat("%03d", $k))
Posted

if i understood you correctly, simply putting the FileSaveDialog right after your includes instead should solve your problem.

Posted

Hi peeps.

I am trying to use the code below, and output the results to a text file. I would like to be able to choose what ever name I want for the output file.

#include <Array.au3>
#include <file.au3>

Dim $FileArray, $BigArray[1][3], $MidArray, $temp
; $FileArray = _FileListToArray("F:\nicole-here\052")
$fold = FileSelectFolder("Choose a folder.", "")
; $FileArray = _FileListToArray("$fold")
$FileArray =_FileListToArray($fold,"*",1)

ReDim $BigArray[$FileArray[0]][3]                   ;will hold all the file names split by "-"
Dim $MidArray[$FileArray[0]]                    ;will hold the mid number (FC)
For $i = 1 To $FileArray[0]
    $temp = StringSplit($FileArray[$i], "-")
    For $j = 1 To $temp[0]
        $BigArray[$i-1][$j-1] = $temp[$j]               ;put the value in the big array
        If $j = 2 Then $MidArray[$i-1] = $temp[$j]  ;put middle string in $MidArray
    Next
Next
;_ArrayDisplay($BigArray, "Big")
;_ArrayDisplay($MidArray, "Mid")
Dim $UniqueArray, $tempArray, $ResultArray
$UniqueArray = _ArrayUnique($MidArray)              ;get unique mid-strings
;_ArrayDisplay($UniqueArray, "Unique")
For $i = 1 To UBound($UniqueArray)-1
    $tempArray = _ArrayFindAll($BigArray, $UniqueArray[$i], 0, 0, 0, 0, 1)  ;get all array indexes for the same mid-string
    ;_ArrayDisplay($tempArray, "Find"&$UniqueArray[$i])
    Dim $ResultArray[UBound($tempArray)][3]
    For $j = 0 To UBound($tempArray) - 1            ;build a temporary array to hold these entries
        $ResultArray[$j][0] = $BigArray[$tempArray[$j]][0]
        $ResultArray[$j][1] = $BigArray[$tempArray[$j]][1]
        $ResultArray[$j][2] = $BigArray[$tempArray[$j]][2]
    Next
    _ArraySort($ResultArray, 0, 0, 0, 2)
    For $k = Number($ResultArray[0][2]) To Number($ResultArray[UBound($ResultArray)-1][2])
        If _ArraySearch($ResultArray, $k, 0, 0, 0, 0, 1, 2) <> -1 Then
            ContinueLoop
        Else
            ; MsgBox(0, "Missing File", $ResultArray[0][0]&"-"&$ResultArray[0][1]&"-"&StringFormat("%03d", $k))
            ; $file = FileOpen("f:\file.txt", 1)
             ; $save = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Jpg (*.jpg)", 18) & ".jpg"
             ; $save = save1
             ; FileWriteLine($save, $ResultArray[0][0]&"-"&$ResultArray[0][1]&"-"&StringFormat("%03d", $k))
             ; $save = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Txt (*.txt)") 
$SaveFile = FileSaveDialog('Would You like to save your array', '', 'Text Files (*.txt)', 2, 'Array.txt')
If @error Then Exit
_FileWriteFromArray($SaveFile, $ResultArray[0][0]&"-"&$ResultArray[0][1]&"-"&StringFormat("%03d", $k))

        EndIf
    Next
Next

I am having trouble with the below code. Autoit prompts me every time it writes a line to to the text file. Also the file "Array.txt" is not being written to. I created the file "Array.txt" to see if that would help. It did not.

$SaveFile = FileSaveDialog('Would You like to save your array', '', 'Text Files (*.txt)', 2, 'Array.txt')
If @error Then Exit
_FileWriteFromArray($SaveFile, $ResultArray[0][0]&"-"&$ResultArray[0][1]&"-"&StringFormat("%03d", $k))

Any help will be appreciated.

Posted

boom!

#include <Array.au3>
#include <file.au3>

Dim $FileArray, $BigArray[1][3], $MidArray, $temp
; $FileArray = _FileListToArray("F:\nicole-here\052")
$fold = FileSelectFolder("Choose a folder.", "")
; $FileArray = _FileListToArray("$fold")
$save = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Txt (*.txt)")
$FileArray = _FileListToArray($fold, "*", 1)

ReDim $BigArray[$FileArray[0]][3] ;will hold all the file names split by "-"
Dim $MidArray[$FileArray[0]] ;will hold the mid number (FC)
For $i = 1 To $FileArray[0]
    $temp = StringSplit($FileArray[$i], "-")
    For $j = 1 To $temp[0]
        $BigArray[$i - 1][$j - 1] = $temp[$j] ;put the value in the big array
        If $j = 2 Then $MidArray[$i - 1] = $temp[$j] ;put middle string in $MidArray
    Next
Next
;_ArrayDisplay($BigArray, "Big")
;_ArrayDisplay($MidArray, "Mid")
Dim $UniqueArray, $tempArray, $ResultArray
$UniqueArray = _ArrayUnique($MidArray) ;get unique mid-strings
;_ArrayDisplay($UniqueArray, "Unique")
For $i = 1 To UBound($UniqueArray) - 1
    $tempArray = _ArrayFindAll($BigArray, $UniqueArray[$i], 0, 0, 0, 0, 1) ;get all array indexes for the same mid-string
    ;_ArrayDisplay($tempArray, "Find"&$UniqueArray[$i])
    Dim $ResultArray[UBound($tempArray)][3]
    For $j = 0 To UBound($tempArray) - 1 ;build a temporary array to hold these entries
        $ResultArray[$j][0] = $BigArray[$tempArray[$j]][0]
        $ResultArray[$j][1] = $BigArray[$tempArray[$j]][1]
        $ResultArray[$j][2] = $BigArray[$tempArray[$j]][2]
    Next
    _ArraySort($ResultArray, 0, 0, 0, 2)
    For $k = Number($ResultArray[0][2]) To Number($ResultArray[UBound($ResultArray) - 1][2])
        If _ArraySearch($ResultArray, $k, 0, 0, 0, 0, 1, 2) <> -1 Then
            ContinueLoop
        Else
            FileWriteLine($save, $ResultArray[0][0] & "-" & $ResultArray[0][1] & "-" & StringFormat("%03d", $k))
        EndIf
    Next
Next

hope this helps :x

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...