Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Looping for files

FolderFileNameFieldName
D:\Data\AEMP_DATA_*.xlsxEmp_code
D:\Data\AEMP_DATA_*.xlsxEmp_salary
D:\Data\BSEGMENT_*.csvSegment_id
D:\Data\BSEGMENT_*.csvSegment_name

Requirement :

Get the list of distinct Folder and loop through them. after scanning each folder(like D:\Data\A) get each files matching with FileName(like EMP_DATA_*.xlsx) and then match Fields of found Files with FieldName in above excel.

I'm stuck in loops which gives error again and again after many try.

Can any Qlik guy help here.

Thanks in Advance

4 Replies
aarkay29
Specialist
Specialist

Something like this

Folders:

Load

    Folder,

    FileName,

    concat(FieldName,',',FieldName) as FieldName

Group by

    Folder,

    FileName;

LOAD

    Folder,

    FileName,

    FieldName

FROM [

    https://community.qlik.com/thread/272196](html, codepage is 1252, embedded labels, table is @1)

Where

    SubField(FileName,'.',-1)='xlsx';

FOR i = 0 to NoOfRows('Folders')-1

LET vFolder = Peek('Folder',$(i), 'Folders');

LET vFileName = Peek('FileName',$(i), 'Folders');

LET vFieldName = Peek('FieldName',$(i), 'Folders');

FOR EACH file in FileList ('$(vFolder)\$(vFileName)');

load

    $(vFieldName)

FROM

    [$(file)] (ooxml, embedded labels, table is Sheet1);

Next file

Next i



I see two types of dataabses Use the code separately for .xlxs and .csv  using where

Where

    SubField(FileName,'.',-1)='xlsx';

As in the "from" statement attributes differ for .xlxs type and csv type


Not applicable
Author

Thanks for reply.

But how it will compare the fieldnames of foundfile to the expected fieldnames in above Fieldname column?

aarkay29
Specialist
Specialist

Can you explain a litle more what you are trying to achieve here ... with example may be better

Not applicable
Author

we have requirement like this :

compare fields of found files in Folders with field name in FieldName and if there is mismatch between them then needs to store this information of tablename and fields in .txt file.

For example:

At location D:\Data\A we have two files with there fields


1)EMP_DATA_1.xlsx  ------------>Emp_code,Emp_salary

2)EMP_DATA_2.xlsx  ------------>Emp_code,Emp_salry


So in above two tables and there fields we can see Emp_salry is mismatch with fields in FieldName of above excels.


Now we need to store information in .txt are as following


Mismatch Table : EMP_DATA_2.xlsx 

Mismatch Field :  Emp_salary


we need to have dynamic approach for all files at different Folder