There is a feature when doing a for each loop called FileList. It’s a way to get a list of files in a directory that matches a wildcard path.

Since this is a parameter of the for each statement and not a function, there is not a lot of information on it. If you have kept up with this blog, you’ll notice that I like doing test cases. So I figured I would build a quick test to have as reference for the future.

One of the things I wanted to determine was what determines the returned list order. So I ended up doing a quick test.

My guess was that there were three options:

  1. Filename
  2. Filetime
  3. Filesize

Result

Filename ascending by alphabetical order.

Test 1

The test is pretty simple. We are going to create three files then read them back in using the filelist mask and capture the order.

The first test is determined as such:

  • File 1: z_Table
    • Highest Alpha
    • Lowest FileTime
    • Middle Size
  • File 2: m_Table
    • Middle Alpha
    • Middle FileTime
    • Highest Size
  • File 3: a_Table
    • Lowest Alpha
    • Highest Filetime
    • Lowest Size

z_Table:
Load
    1 as FieldA
AutoGenerate
    (1000);
    
    
    
m_Table:
Load
    1 as FieldB
AutoGenerate
    (100000);


a_Table:
Load
    1 as FieldC
AutoGenerate
    (10);
    

result:
Load
    Num(Null()) as Order,
    Null()      as File
AutoGenerate
    (0);
    
    
For each t in 'z_Table', 'm_Table', 'a_Table'

    Trace ---------------- $(t);

    Store $(t) into [lib://QVD/test/for-each-order/$(t).qvd](qvd);
  
Next t;


For each file in FileList('lib://QVD/test/for-each-order/*.qvd')

    Concatenate(result)
    Load
        RowNo() as Order,
        '$(file)' as File   
    AutoGenerate
        (1);

Next file;

Test 2

In this test I reversed the table store order, which reversed the filetime order.

  • File 1: z_Table
    • Highest Alpha
    • Highest FileTime
    • Middle Size
  • File 2: m_Table
    • Middle Alpha
    • Middle FileTime
    • Highest Size
  • File 3: a_Table
    • Lowest Alpha
    • Lowest Filetime
    • Lowest Size
z_Table:
Load
    1 as FieldA
AutoGenerate
    (1000);
    
    
    
m_Table:
Load
    1 as FieldB
AutoGenerate
    (100000);


a_Table:
Load
    1 as FieldC
AutoGenerate
    (10);
    

result:
Load
    Num(Null()) as Order,
    Null()      as File
AutoGenerate
    (0);
    
    
For each t in 'a_Table', 'm_Table', 'z_Table'

    Trace ---------------- $(t);

    Store $(t) into [lib://QVD/test/for-each-order/$(t).qvd](qvd);
  
Next t;


For each file in FileList('lib://QVD/test/for-each-order/*.qvd')

    Concatenate(result)
    Load
        RowNo() as Order,
        '$(file)' as File   
    AutoGenerate
        (1);

Next file;

Test 3

In this test I reversed the file size for z_Table and a_Table.

  • File 1: z_Table
    • Highest Alpha
    • Highest FileTime
    • Lowest Size
  • File 2: m_Table
    • Middle Alpha
    • Middle FileTime
    • Highest Size
  • File 3: a_Table
    • Lowest Alpha
    • Lowest Filetime
    • Middle Size
z_Table:
Load
    1 as FieldA
AutoGenerate
    (10);
    
    
    
m_Table:
Load
    1 as FieldB
AutoGenerate
    (100000);


a_Table:
Load
    1 as FieldC
AutoGenerate
    (1000);
    

result:
Load
    Num(Null()) as Order,
    Null()      as File
AutoGenerate
    (0);
    
    
For each t in 'a_Table', 'm_Table', 'z_Table'

    Trace ---------------- $(t);

    Store $(t) into [lib://QVD/test/for-each-order/$(t).qvd](qvd);
  
Next t;


For each file in FileList('lib://QVD/test/for-each-order/*.qvd')

    Concatenate(result)
    Load
        RowNo() as Order,
        '$(file)' as File   
    AutoGenerate
        (1);

Next file;

Result

Every test returned the same thing: a_Table was the first within the list. This means that the FileList mask returns and alphabetical file list.