Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

For Each statement

Hi,

I've the following sub to read all files in a specific folder. For some reason (probably because the files are shared) there are junk files in the folder (starts with ~$ and filesize is 0kb). The sub fails because of these files. How do I modify the sub so it doesn't try to read these files?

Thanks,
Jonas

Sub readFiles (root)

    For each File in filelist (root & '\*.xlsx')

        Npi_Bom_template:

        LOAD RecNo() as counterBOM,

            ASMBLY,

             fileName() as [Project Name],

             PART,

             QTY,

             CUSTPN

        From [$(File)] (ooxml, embedded labels, header is 4 lines, table is [BOM-Report]);

    Next File;

End sub;

Call readFiles ('S:\_Bom_Reports');

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

what about disregarding ~$ files, using sth like this:

Sub readFiles (root)

    For each File in filelist (root & '\*.xlsx')

    vsFileCheck = index(File,'~$');

        if vsFileCheck=0 then

             Npi_Bom_template:

             LOAD RecNo() as counterBOM,

             ASMBLY,

             fileName() as [Project Name],

             PART,

             QTY,

             CUSTPN

             From [$(File)] (ooxml, embedded labels, header is 4 lines, table is [BOM-Report]);

       endif

    Next File;

End sub;

Call readFiles ('S:\_Bom_Reports');

View solution in original post

2 Replies
whiteline
Master II
Master II

Hi.

You can either check the file size with FileSize() function before load or modify the wildcard in "filelist (root & '\*.xlsx')" to consider only files having some permanent prefix.

Anonymous
Not applicable
Author

what about disregarding ~$ files, using sth like this:

Sub readFiles (root)

    For each File in filelist (root & '\*.xlsx')

    vsFileCheck = index(File,'~$');

        if vsFileCheck=0 then

             Npi_Bom_template:

             LOAD RecNo() as counterBOM,

             ASMBLY,

             fileName() as [Project Name],

             PART,

             QTY,

             CUSTPN

             From [$(File)] (ooxml, embedded labels, header is 4 lines, table is [BOM-Report]);

       endif

    Next File;

End sub;

Call readFiles ('S:\_Bom_Reports');