Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

camjvine18
Contributor

Load multiple CSV files into a table

I have attempted to adapt code from other Qlik community threads but still to no avail. All i want is to put together all the csv files in a folder into one table.

Neither of these scripts work

1) Provides no error message

vPath = 'C:\Dropbox\Trading\Data\'

For each File in FileList('$(vPath)*.csv')

TableName:

Load

Date(Date#([@1], 'DD/MM/YYYY') ) AS [Date],

[@2] AS [Open],

[@3] AS [High],

[@4] AS [Low],

[@5] AS [Close],

[@6] As [Volume],

[@7] As [Open Interest],

    LEFT(FileBaseName (), 6) as Code_CSV

From $(File);

NEXT

2) Does not recognise C:

For each vFileName in Filelist ('lib://C:\Dropbox\Trading\Data\*.csv')

      Load *,

Date(Date#([@1], 'DD/MM/YYYY') ) AS [Date],

[@2] AS [Open],

[@3] AS [High],

[@4] AS [Low],

[@5] AS [Close],

[@6] As [Volume],

[@7] As [Open Interest],

    LEFT(FileBaseName (), 6) as Code_CSV

      From [$(vFileName)]

      (txt, utf8, embedded labels, delimiter is ',', msq);

Next vFileName

21 Replies
mdmukramali
Valued Contributor II

Re: Load multiple CSV files into a table

Hi,

Can you try the below script:

Set vConcatenate = ;

FileList:

LOAD

'' AS SourceFile

AUTOGENERATE 0;

sub ScanFolder(Root)

for each FileExtension in 'Qvd'

for each FoundFile in filelist( Root & '\*.' & FileExtension)

  Table:

LOAD District,

    [Category Name],

    [Sub Category],

    [Item Name],

    [Sales Amt TW],

    [Sales Amt LW],

    FileBaseName() as FileName

FROM

$(FoundFile)(qvd);                       

Set vConcatenate = Concatenate;

next FoundFile

next FileExtension

for each SubDirectory in dirlist( Root & '\*' )

call ScanFolder(SubDirectory)

next SubDirectory

end sub

Call ScanFolder('C:\Users\Qlik\Documents\QVD\') ;

change the file extension from qvd to csv and path of the data.

else share the sample excel file.

camjvine18
Contributor

Re: Load multiple CSV files into a table

Did not load anything as the CSV is red in the script at $(FoundFile)(CSV)

Re: Load multiple CSV files into a table

mdmukramali
Valued Contributor II

Re: Load multiple CSV files into a table

Hi,

you have to adjust the script.

From

$(FoundFile)

(ooxml, embedded labels, header is 1 lines, table is Yearly)

for Qvd no need of (ooxml, embedded labels, header is 1 lines, table is Yearly).


for CSV you have to add the following.


else share at least one CSV file.

Thanks,

Mukram.

pradosh_thakur
Valued Contributor III

Re: Load multiple CSV files into a table

may be this. The chnaged part is in red

vPath = 'C:\Dropbox\Trading\Data\'

For each File in FileList('$(vPath)'&'*.csv')

TableName:

Load

Date(Date#([@1], 'DD/MM/YYYY') ) AS [Date],

[@2] AS [Open],

[@3] AS [High],

[@4] AS [Low],

[@5] AS [Close],

[@6] As [Volume],

[@7] As [Open Interest],

    LEFT(FileBaseName (), 6) as Code_CSV

From '$(File)'  (txt, utf8, embedded labels, delimiter is ',', msq);

NEXT

regards

Pradosh

camjvine18
Contributor

Re: Load multiple CSV files into a table

Still does not read the file.

camjvine18
Contributor

Re: Load multiple CSV files into a table

Do you mean like this? If so it did not work.

FROM

$(FoundFile)(CSV)(ooxml, embedded labels, header is 1 lines, table is Yearly);

I have example files to the initial post.

camjvine18
Contributor

Re: Load multiple CSV files into a table

Example files

camjvine18
Contributor

Re: Load multiple CSV files into a table

Using that I still get an error in connection not found to C, ie. call DoDir ('lib://C:\Dropbox\Trading\Data')

Community Browser