31290 Posted February 24, 2017 Posted February 24, 2017 (edited) Hi guys, I'd like to write a piece of tool that would allow me to update a certain field in our Active Directory from a comma separated csv file composed like this: This file, automatically generated, can hold more than 10k lines. Thus, I need column A to be in one variable, column B in a second one and column C in a third one. I'm really missing this part as updating the AD is fairly easy once the 3 variable are populated. I see things like this: Quote Read line 1 Do AD update Read line 2 Do AD update ... End Of File Here's my attempts at the moment: #include <File.au3> #include <Array.au3> Global $csv_file = @DesktopDir & "\Book1.csv" Global $aRecords If Not _FileReadToArray($csv_file,$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) ; Shows the line that was read from file $csv_line_values = StringSplit($aRecords[$x], ",",1) ; Splits the line into 2 or more variables and puts them in an array ; _ArrayDisplay($csv_line_values) ; Shows what's in the array you just created. ; $csv_line_values[0] holds the number of elements in array ; $csv_line_values[1] holds the value ; $csv_line_values[2] holds the value ; etc Msgbox(0, 0, $csv_line_values[1]) Next Any help on this please? Thanks in advance -31290- Edited February 24, 2017 by 31290 solved ~~~ Doom Shall Never Die, Only The Players ~~~
rootx Posted February 24, 2017 Posted February 24, 2017 #include <File.au3> #include <Array.au3> Global $csv_file = @DesktopDir & "\Book1.csv" Global $aRecords If Not _FileReadToArray($csv_file,$aRecords) Then ; MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to UBound($aRecords) -1 ConsoleWrite("ROW "&$x &" "&$aRecords[$x]&@CRLF) ; Shows the line that was read from file $csv_line_values = StringSplit($aRecords[$x], ",",1) ; Splits the line into 2 or more variables and puts them in an array For $z = 1 to UBound($csv_line_values) -1 If $z = 1 Then ConsoleWrite(" A " &$csv_line_values[$z]&@CRLF) ElseIf $z = 2 Then ConsoleWrite(" B " &$csv_line_values[$z]&@CRLF) ElseIf $z = 3 Then ConsoleWrite(" C " &$csv_line_values[$z]&@CRLF) EndIf Next ; _ArrayDisplay($csv_line_values) ; Shows what's in the array you just created. ; $csv_line_values[0] holds the number of elements in array ; $csv_line_values[1] holds the value ; $csv_line_values[2] holds the value ; etc ; Msgbox(0, 0, $csv_line_values[1]) Next 31290 1
31290 Posted February 24, 2017 Author Posted February 24, 2017 Perfect, Thanks ~~~ Doom Shall Never Die, Only The Players ~~~
Subz Posted February 24, 2017 Posted February 24, 2017 Would like to add you can also use Excel UDF to create your array #include <Array.au3> ;~ Only required for _ArrayDisplay() #include <Excel.au3> ;~ Excel File (.xlxx, .csv) file path $sExcelFile = @DesktopDir & "\Book1.csv" ;~ Open Excel Object $oExcel = _Excel_Open (False) ;~ Open the Workbook $oWorkbook = _Excel_BookOpen($oExcel, $sExcelFile, True, False) ;~ Read the Workbook to an array $aArray = _Excel_RangeRead($oWorkbook) ;~ Display the Array _ArrayDisplay($aArray) ;~ Close the WorkBook _Excel_BookClose($oWorkbook) ;~ Close the Excel Object _Excel_Close($oExcel)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now