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

count files in folder

hi,

did anybody know a way to count the files in a defined folder?

I have a folder in which are a lot of powerpoint files. I'd like to open the newest file from this folder with qlikview.

Many Thanks.

Hernandez

1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

Hello,

Do a loop to search for files. The following is basically the same that the sample in the Reference Manual example and loads the most recent:

Sub DoDir (Root)

     For Each Ext In 'qvd' // filetype to search for in current directory

          For Each File In FileList (Root & '\*.' & Ext)

                    Files:

                    Load '$(File)' as Name,

                     FileTime('$(File)') as FileTime,

                     RangeSum(Peek('FileCount'), 1) as FileCount

                    Autogenerate 1;

          Next File

     Next Ext

     For Each Dir In DirList (Root & '\*') // search in sundirectories

          Call DoDir (Dir)

     Next Dir

End Sub

Call DoDir ('C:\QlikView\QVD'); // Starting point

MostRecentFileName:

FIRST 1 LOAD Name AS MostRecentFileName

RESIDENT Files

ORDER BY FileTime DESC;

LET vFileToLoad = FieldValue('MostRecentFileName', 1);

DROP TABLE MostRecentFileName;

MostRecentQVD:

LOAD *

FROM $(vFileToLoad) (qvd);

Hope that helps.

View solution in original post

5 Replies
Miguel_Angel_Baeyens

Hello,

Do a loop to search for files. The following is basically the same that the sample in the Reference Manual example and loads the most recent:

Sub DoDir (Root)

     For Each Ext In 'qvd' // filetype to search for in current directory

          For Each File In FileList (Root & '\*.' & Ext)

                    Files:

                    Load '$(File)' as Name,

                     FileTime('$(File)') as FileTime,

                     RangeSum(Peek('FileCount'), 1) as FileCount

                    Autogenerate 1;

          Next File

     Next Ext

     For Each Dir In DirList (Root & '\*') // search in sundirectories

          Call DoDir (Dir)

     Next Dir

End Sub

Call DoDir ('C:\QlikView\QVD'); // Starting point

MostRecentFileName:

FIRST 1 LOAD Name AS MostRecentFileName

RESIDENT Files

ORDER BY FileTime DESC;

LET vFileToLoad = FieldValue('MostRecentFileName', 1);

DROP TABLE MostRecentFileName;

MostRecentQVD:

LOAD *

FROM $(vFileToLoad) (qvd);

Hope that helps.

Not applicable
Author

That works!

Thanks! Smile

Not applicable
Author

Nice - thanks for that reply.  Exactly what I needed.

Not applicable
Author

This is awesome! I added the FileSize as well so I can quickly comb through and find the largest QVW or QVDs in specific folders or on specific drives.

Very nice.

Thank you.

Tyler

Anonymous
Not applicable
Author

Dear All,

In my case it is not storing the Name of the File into Name Field

i.e Load '$(File)' as Name

Please Help On this !!!