Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

how to load all files from directory


Hi Friends

I have three folders in D drive each having some text files.

I want to run load statement to load all the text files from folders.

Thanks

Tags (1)
9 Replies
MVP
MVP

Re: how to load all files from directory

Hi,

Try like this

Data:

LOAD

*

FROM Folder1\*.txt;

Concatenate(Data)

LOAD

*

FROM Folder2\*.txt;

Concatenate(Data)

LOAD

*

FROM Folder3\*.txt;

Regards,

Jagan.

Not applicable

Re: how to load all files from directory

Thanks Jagan

But the format for all text file are same so I want to load all text files at a go from all folders.

Thanks


Luminary
Luminary

Re: how to load all files from directory

Try something like:

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

Load '$(Dir & '\*.txt')'   <- not sure if this statement works

next Dir

MVP
MVP

Re: how to load all files from directory

Hi Pavan,

Then you have to loop the folders using For loop or if it is just 3 folders then you can use above script.

FOR Each Dir in dirlist (Root&' \*' )

Data:

LOAD

*

FROM $(Dir)\*.txt;

NEXT Dir

Regards,

Jagan.

mjayachandran
Contributor II

Re: how to load all files from directory

You can also do it like,

Config:

Load * inline [

path,

'c:\'

'D:\'

'c:\Data\'

];

For i=0 to noofrows('Config')-1

let path=peek('path',0,'Config');

Test:

Load

......................

your fields

.....................

From

$(path)*.txt (txt, codepage is 1252, no labels, delimiter is ' ', msq);

In the config you can define all the path u want to load

Not applicable

Re: how to load all files from directory

Jagan I am using the code. The highlighted is my path name where all the text files are there. Can you send me the code please

Load *

FROM

[D:\test\9_30\9_30\*.txt]

Not applicable

Re: how to load all files from directory

Jagan

Could you please explain the code how it works.

Thanks

mjayachandran
Contributor II

Re: how to load all files from directory

Config:

Load * inline [

path, Location

Path1, 'D:\test\9_30\9_30\' ,

Path2, 'D:\test\9_31\9_31\'

];

For i=0 to NoOfRows('Config')-1

let path= Peek('Location', $(i), 'Config');

Table:

Load

*

From $(path)*.txt (txt, codepage is 1252, no labels, delimiter is ' ', msq);

Next i

Drop Table Config;

MVP
MVP

Re: how to load all files from directory

Hi,

The below code loops through all the folders in the given root path using FOR EACH loop and loads all the text files in each folder, we have used wildcard characters *.txt to load only txt files.

SET Root = 'D:\test\9_30\9_30';

FOR Each Dir in dirlist (Root&' \*' )

Data:

LOAD

*

FROM $(Dir)\*.txt (txt, codepage is 1252, no labels, delimiter is ' ', msq);

NEXT Dir

Community Browser