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 import data when file name matches

Hi Friends,

I have month wise data in D drive. Say 09-2014,08-2014 and 07-2014.

How to get the data into qlikview based on the file name.

Thanks


Tags (1)
1 Solution

Accepted Solutions
marcarreras
Valued Contributor

Re: how to import data when file name matches

Hello,

As I don't know your exact purpose, here you have some tools for file management:

If you want to know if a file exists or not:

if filetime('c:\mydata\my.qvd) then

      //qvd exists

else

      //qvd doesn't exist

end if

You can go further the filetime function to control which file you want to import or not, depending of its creation timestamp.

If you want to have a look in a folder:

Directory;

FOR Each File in filelist ('.\BUFFER_*.xlsx')

  LOAD *

  FROM

  '$(File)'

  (ooxml, no labels, table is Sheet1);

NEXT File;

Maybe your solution needs a combination of all these.

Hope it helps.

Marc.

5 Replies
michielvandegoo
Valued Contributor

Re: how to import data when file name matches

Use a * as a wildcard instead of the full file name. The files will be concatenated if the fields have identical names.

So for instance:

load .... from 09-2014.qvd; will become

load ... from *.qvd;

marcarreras
Valued Contributor

Re: how to import data when file name matches

Hello,

As I don't know your exact purpose, here you have some tools for file management:

If you want to know if a file exists or not:

if filetime('c:\mydata\my.qvd) then

      //qvd exists

else

      //qvd doesn't exist

end if

You can go further the filetime function to control which file you want to import or not, depending of its creation timestamp.

If you want to have a look in a folder:

Directory;

FOR Each File in filelist ('.\BUFFER_*.xlsx')

  LOAD *

  FROM

  '$(File)'

  (ooxml, no labels, table is Sheet1);

NEXT File;

Maybe your solution needs a combination of all these.

Hope it helps.

Marc.

Not applicable

Re: how to import data when file name matches

Please explain the second code.

lets I have a file name AAA.txt and BBB.txt. can I  load each based on the above code??

michielvandegoo
Valued Contributor

Re: how to import data when file name matches

Load with a wildcard (*):

*.txt will load both files and concatenate the same fields.

marcarreras
Valued Contributor

Re: how to import data when file name matches

In case you want to load every txt file in this folder, do:

load ... from *.txt;

In case you need to load both files but you can not asure they exist, do:

if filetime('AAAA.txt') then

      load * from AAAA.txt;

end if

if filetime('BBBB.txt') then

      load * from BBBB.txt;

end if

Community Browser