locked
Import csv files RRS feed

  • Question

  • I have many csv files, like below and need to import into 2D array or hash (whichever is faster for later process).
    So the first element is string containing names and the second element is array/hash containing a list of numbers for each name

    File1.csv
    Name, Number
    ABC,111
    DEF,222
    GHI,333

    File2.csv
    Name, Number
    ABC,444
    DEF,555
    GHI,666

    File3.csv
    Name, Number
    ABC,777
    DEF,888
    GHI,999


    PS C:\> $a[0][0]
    ABC
    PS C:\> $a[0][1]
    111
    444
    777
    PS C:\> $a[1][0]
    DEF
    PS C:\> $a[1][1]
    222
    555
    888
    PS C:\> $a[2][0]
    GHI
    PS C:\> $a[2][1]
    333
    666
    999
    • Edited by Ian3 Sunday, June 17, 2018 12:05 AM
    Saturday, June 16, 2018 11:58 PM

All replies

  • You forgot to post your code.   What is the question? 

    To load CSV use "Import-Csv".  Instructions and examples are in the help.  Use "Group-Object" to create the list  of collections.


    \_(ツ)_/

    Sunday, June 17, 2018 12:41 AM
  • I know $a = Import-csv C:\File1.csv can import file1.csv into array $a but not sure how to continue to import other files into the same array $a
    Sunday, June 17, 2018 2:28 AM
  • If you would actually read the help you would have seen the answer.

       -Path <String[]>
           Specifies the path to the CSV file to import. You can also pipe a path to Import-Csv .


    \_(ツ)_/

    • Proposed as answer by BOfH-666 Sunday, June 17, 2018 7:25 AM
    Sunday, June 17, 2018 2:49 AM