Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
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
Partner - Specialist II
Partner - Specialist II

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

View solution in original post

9 Replies
p_verkooijen
Partner - Specialist
Partner - Specialist

You can just use this simple version.

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


Not applicable
Author

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
Partner - Specialist
Partner - Specialist

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
Partner - Specialist II
Partner - Specialist II

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

hic
Former Employee
Former Employee

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
Author

Thanks Jamie

It worked.

pandiarajan
Creator
Creator

Henric Cronström

Dear Henric Sir,

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

hic
Former Employee
Former Employee

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
Contributor
Contributor

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;