Jump to content

Read and split CSV per line


gniuz
 Share

Recommended Posts

Hi,

I'm new to AutoIt and have been focussing on Powershell instead. However, there's a need to accomplish something that I (even with the help of the WASP PSSnapin) can't get to work.

Can anyone please provide me an autoit translation of the following powershell script? It basically just reads a csv and splits it per line. I've found some references on this forum but they don't seem to read and split the stuff per line. Many thanks!

Input.csv:

----------

username, oldpw, newpw

jimbo, seed, homebrew

treehugginghippie, green, leaf

terminatorx, bass, howlowcanyougo

powershell.ps1:

---------------

$csv_file = $env:systemdrive+'\input.csv'

$csv_info = Import-Csv $csv_file

foreach ($line in $csv_info) {

& bla.exe -username $($line.username) -oldpw $($line.oldpw) -newpw $($line.newpw)

}

Edited by gniuz
Link to comment
Share on other sites

I don't know powershell but if you wanna read a multilined file and split it per line you could do _FileReadToArray. It would read that text document and put each line into a cell in the array then you could do whatever you wanted with it from there.

Edited by Onichan
Link to comment
Share on other sites

Something like:

#include <file.au3>
_FileReadToArray("filename",$aArray)
For $iCount = 1 To $aArray[0]
    $aFields = StringSplit($aArray[$iCount],",")
    ShellExecuteWait("bla.exe","-username " & $aFields[1] & " -oldpw " & $aFields[2] & " -newpw " & $aFields[3])
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Something like:

#include <file.au3>
_FileReadToArray("filename",$aArray)
For $iCount = 1 To $aArray[0]
    $aFields = StringSplit($aArray[$iCount],",")
    ShellExecuteWait("bla.exe","-username " & $aFields[1] & " -oldpw " & $aFields[2] & " -newpw " & $aFields[3])
Next

Wow guys, thanks for the extremely quick reply. I'll start experimenting right away and let you know. Tnx!
Link to comment
Share on other sites

That went great.. Now here's something else.

What if the CSV file would be an XML file. How would this change the script?

input.xml:

----------

<UserList>
            <User>
                <Name>jimbo</Name>
                <OldPW>seed</OldPW>
                <NewPW>homebrew</NewPW>
            </User>
            <User>
                <Name>treehugginghippie</Name>
                <OldPW>green</OldPW>
                <NewPW>leaf</NewPW>
            </User>
            <User>
                <Name>terminatorx</Name>
                <OldPW>bass</OldPW>
                <NewPW>howlowcanyougo</NewPW>
            </User>

</UserList>

Once again, thanks for your time!

Link to comment
Share on other sites

Maybe this can help with XML: XML DOM Wrapper

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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