Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

Not applicable

Load Multiple CSV file from the specified directory into a table

Hi

I need to load the csv file from the specific directory into a table.

Can anyone tell me how to do it.

For each csvFile in filelist ('$(vDirPath)*.csv')

<TableName>:

LOAD

From $(csvfile)

(txt, codepage is 1252, embedded labels, delimiter is ',', msq)

next csvfile

I am getting on error that the from filename is missing.

Thanks

Ramesh

1 Solution

Accepted Solutions
jaimeaguilar
Valued Contributor II

Re: Load Multiple CSV file from the specified directory into a table

You can try with something like this:

vPath = File directory where you're storing xls files

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

TableName:

Load

Field1,

Field2,

FieldN

From $(File);

NEXT

9 Replies
p_verkooijen
Valued Contributor

Re: Load Multiple CSV file from the specified directory into a table

You can just use this simple version.

load * from dirpath\*.csv  (txt, codepage is 1252, embedded labels, delimiter is ',', msq);


Not applicable

Re: Load Multiple CSV file from the specified directory into a table

Thanks Paul

I was doing this initially.  But i would like to store it into a table and also i get a file on monthly basis so i decided to put into the for loop to concatenate the data into table. Is there anyway i scan through the files in the directory and load the same into the table.

Ramesh

p_verkooijen
Valued Contributor

Re: Load Multiple CSV file from the specified directory into a table

of course, infact the syntax should be right.

maybe a copy / paste error, but the from variable is not the same as the for each. it has to be exactly the same upper an lower case.

you can use the csvfile variable in the load

try the debug mode

jaimeaguilar
Valued Contributor II

Re: Load Multiple CSV file from the specified directory into a table

You can try with something like this:

vPath = File directory where you're storing xls files

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

TableName:

Load

Field1,

Field2,

FieldN

From $(File);

NEXT

Employee
Employee

Re: Load Multiple CSV file from the specified directory into a table

In principle you are doing the right thing. Two things though:

  • Is vDirPath defined?
  • The 'From $(csvfile)' should be quoted: From [$(csvfile)]

Further, I agree with Paul that you should use the debugger to find the error. Press "Step" until you come to the relevant statements, and check that the For-Next and the Load have correct parameters.

Debug.png

HIC

Not applicable

Re: Load Multiple CSV file from the specified directory into a table

Thanks Jamie

It worked.

pandiarajan
Contributor

Re: Load Multiple CSV file from the specified directory into a table

Henric Cronström

Dear Henric Sir,

     i want to apply same mechanism From FTP Server. i have been struggle past 10 days

Employee
Employee

Re: Load Multiple CSV file from the specified directory into a table

I haven't tried it, but I doubt that this is possible using the FileList() function.

You could perhaps try to execute a ls command, pipe this into a local file, and read this file with QlikView. But, sorry to say, I am not an expert on ftp, so I could be wrong here...

HIC

peter_magnusson
New Contributor

Re: Load Multiple CSV file from the specified directory into a table

I have actually been trying the same thing a couple of hours and by combining the mentioned solution in this post with a solution from another i came up with a nice solution. You can probably just copy/paste if you want to try it. My solution fetches all the xml files in a folder so you can just change "*.xml" to your preferred file ending.

vPath = [ftp://your_username:your_password@your_serveraddress/folder_where_the_files_are_stored]

Directory;

FOR Each File in filelist ('$(vPath)*.xml')

LOAD

Fieldname1,

Fieldname2

FROM

'$(File)'

(XmlSimple, Table is [Database/Data]);

NEXT File;

Community Browser