Qlik Community

Ask a Question

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
Talk to Experts Tuesday, January 26th at 10AM EST: Qlik Sense. REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Contributor II
Contributor II

Auto load source file and generate qvd with same name

Hi Guys,

Query :

I have two folders (Source) and (Source QVD)

Now, I am trying load new source files from (source) folder where only new source files will be fetched whose QVD is not generated in (Source QVD) folder.

example :

i have a.txt , b.txt files in (Source) folder and a.qvd in (source QVD) folder

now after i reload i want only qvd generated of b.txt source file

condition:

Source file name and generated QVD of that file must have same name

My Script:   I am trying with following script but failing somewhere


FOR Each File in filelist ('C:\Users\Sachin\Desktop\Test\Autoload\source\*.txt')

FileDirectory:

LOAD

subfield(SubField('$(File)','\',8),'.',1) as Name

autogenerate 1;

NEXT File

FOR Each File in filelist ('C:\Users\Sachin\Desktop\Test\Autoload\SourceQVD\*.qvd')

Left Join

LOAD

subfield(SubField('$(File)','\',8),'.',1) as Name,

1 as flag

autogenerate 1;

NEXT File

NewSource:

load RowNo(),

Name,

flag

Resident FileDirectory

where flag <> 1;

DROP Table FileDirectory;

let vSourceFileCount = NoOfRows('NewSource');

for i=0 to $(vSourceFileCount)

let vQvdFileName = Peek('Name',$(i),'NewSource');

// qvd logic

NEXT i;

//QVD GENERATE LOGIC

for j=0 to $(vSourceFileCount)

let vSourcefilename = Peek('Name',$(j),'NewSource');

'$(vSourcefilename)':

load *

from C:\Users\Sachin\Desktop\Test\Autoload\qvwfilename autoload source data\*.txt;

store $(vSourcefilename) into C:\Users\Sachin\Desktop\Test\Autoload\qvwfilename auto load source data\$(vSourcefilename).qvd;

next j


Thanks and Regards,

Sachin


1 Solution

Accepted Solutions
Contributor II
Contributor II

Thanks Peter,

you Rocked

View solution in original post

3 Replies

IMHO the following simpler version does what you ask. Unless I missed some obvious requirements.

LET vSourcePath = 'C:\Users\Sachin\Desktop\Test\Autoload\';

FOR Each File in filelist('$(vSourcePath)\Source\*.txt')

  LET vBaseName = mid(subfield('$(File)', '\', -1), 1, index(subfield('$(File)', '\', -1), '.', -1)-1);

  IF IsNull(filetime('$(vSourcePath)\SourceQVD\$(vBaseName).qvd')) THEN

    TrfTable:

    LOAD * FROM [$(vSourcePath)\Source\$(vBaseName).txt] (txt, codepage is 1252, embedded labels, delimiter is ',', msq);

    STORE TrfTable INTO [$(vSourcePath)\SourceQVD\$(vBaseName).qvd] (qvd);

    DROP Table TrfTable;

  END IF

NEXT

LET vBaseName=;

LET File=;

You must adjust the file options in the LOAD statement to correspond to the contents of your text files. These match my test data, and may not suit your situation.

Best,

Peter

Contributor II
Contributor II

Thanks Peter,

you Rocked

View solution in original post

Thanks, Sachin.

BTW you have an original way to close the discussion.