Jump to content

csvlibs


Recommended Posts

sorry newbie question

I have been using the csvlib.au3 files for reading csvs into my scripts and they stop working the other day, I realised there had been an update to this with the _csv_lib_v1.3.au3 files.

I then noticed that the _csvgetfields function has been replaced, but I am not entirely understanding what the like for like replacement would be in the v1.3 file

is it _CSVFileReadRecords so I would simply replace _csvgetfields with this (see old example below)

$VarGroupName = _CSVGetField ($File, 1,$i, -1, -1, 0)

($file declared earlier in script)

Secondly, in reading the help, I notice there is the ability to read an entire csv into an array.

would this be a quicker method of looping through a csv file for variables?

at the moment, I am doing the below and I noticed its very slow, was wondering if the array method would be quicker?

Could someone point me in the right direction?

thanks

tony

#include "_CSVLib_V1.3.au3"

#include "CSVLib.au3"

#include <Array.au3>

#Include <File.au3>

#include <Process.au3>

#include <INet.au3>

; select the source CSV file for adding members in the format of groupname,user to be added

$File = FileOpenDialog('Open csv', "h:\mydocs\utils\gam" & '\', 'Csv files (*.csv)', 1, 'augroups.csv')

; set number of rows in csv as reference object

$CountLines=_FileCountLines($File)

; show number of rows in csv

MsgBox(0, 'rows', $Countlines)

; get records separated by ,

$i = 1

While $i <= $countlines

$VarGroupName = _CSVGetField ($File, 1,$i, -1, -1, 0)

$VarAlwExt = _CSVGetField ($File, 2, $i, -1, -1, 0)

$VarMsgMod = _CSVGetField ($File, 3, $i, -1, -1, 0)

$VarShwGrp = _CSVGetField ($File, 4, $i, -1, -1, 0)

$VarInvite = _CSVGetField ($File, 5, $i, -1, -1, 0)

$VarJoin = _CSVGetField ($File, 6, $i, -1, -1, 0)

$VarPost = _CSVGetField ($File, 7, $i, -1, -1, 0)

$VarViewGrp = _CSVGetField ($File, 8, $i, -1, -1, 0)

$VarViewMem = _CSVGetField ($File, 9, $i, -1, -1, 0)

$i = $i + 1

; Declare the dos command to be Run

Dim $DOSCMD = String("h:\mydocs\utils\gam\gam update group "&$VarGroupName&" allow_external_members "&$VarAlwExt&" message_moderation_level "&$VarMsgMod&" show_in_groups_directory "&$VarShwGrp&" who_can_invite "&$VarInvite&" who_can_join "&$VarJoin&" who_can_post_message "&$VarPost&" who_can_view_group "&$VarViewGrp&" who_can_view_membership "&$VarViewMem)

; MsgBox(0, 'Output', $DOSCMD)

$rc = _RunDOS ( $DOSCMD )

Sleep(1000) ;one seconds

WEnd

MsgBox(0,"Groups Update", "all done, please check")

Link to comment
Share on other sites

#Include <File.au3>
#include <Process.au3>

Global $data

; select the source CSV file for adding members in the format of groupname,user to be added
$File = FileOpenDialog('Open csv', "h:mydocsutilsgam" & '', 'Csv files (*.csv)', 1, 'augroups.csv')

; load CSV to array variable
_FileReadToArray($File, $data)

; show number of rows in csv
MsgBox(0, 'rows', $data[0])

; get records separated by ,
For $i = 1 to $data[0]
    $line = $data[$i]
;   ConsoleWrite($line & @CRLF)
    $line = StringSplit($line,',')

    $VarGroupName = $line[1]
    $VarAlwExt = $line[2]
    $VarMsgMod = $line[3]
    $VarShwGrp = $line[4]
    $VarInvite = $line[5]
    $VarJoin = $line[6]
    $VarPost = $line[7]
    $VarViewGrp = $line[8]
    $VarViewMem = $line[9]

    ; Declare the dos command to be Run
    $DOSCMD = String("h:mydocsutilsgamgam update group "&$VarGroupName&" allow_external_members "&$VarAlwExt&" message_moderation_level "&$VarMsgMod&" show_in_groups_directory "&$VarShwGrp&" who_can_invite "&$VarInvite&" who_can_join "&$VarJoin&" who_can_post_message "&$VarPost&" who_can_view_group "&$VarViewGrp&" who_can_view_membership "&$VarViewMem)

    ; MsgBox(0, 'Output', $DOSCMD)
    $rc = _RunDOS ( $DOSCMD )
    Sleep(1000) ;one seconds
Next

MsgBox(0,"Groups Update", "all done, please check")

EDIT: there is no error checking ...

Edited by Zedna
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...