Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Count number of file in folder

Hi I have a question,

I want to count number of file that start with DATA*

There area 3 qvd files in my folder, they area DATA1, DATA2, and DATA3.

If file start with DATA exist i want to give a flag.

I have try using this one

LET vListqvdexists=isnull(QvdCreateTime('QVD\DATA*.qvd'));

But it doesn't work.

Do you have any solution ?

6 Replies
Kushal_Chawda

try this


LET vListqvdexists=if(Filesize('..\QVD\DATA*.qvd')>0,1,0);

jonathandienst
Partner - Champion III
Partner - Champion III

I don't think that the QVD file functions or FileSize can take a wildcard file name. I suggest this script:

Let vListqvdexists = 0;

For Each vFile in FileList('QVD\DATA*.qvd')

  Let vListqvdexists = 1;

Next

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
tamilarasu
Champion
Champion

Lejours,

Try,

Set vRoot = 'C:\Users\Tamil.Nagaraj\Desktop\Path';

FOR Each File in filelist ('$(vRoot)'&'\*.qvd')
let vBaseName = subfield('$(File)','\',SubStringCount('$(File)','\')+1);

If WildMatch('$(vBaseName)','DATA*') Then
Files:
Load '$(vBaseName)'  as Name autogenerate 1;
ENDIF
next File
Let vListqvdexists = NoOfRows('Files');

DROP Table Files;

qliksus
Specialist II
Specialist II

May be something like this

load count(Name) as Filecnt

load filebasename() as Name

from C:\temp\Data* ;

mikael_bjaveclo
Partner - Contributor II
Partner - Contributor II

This is a fast way to get the number of files.

I tested the code with 10000 qvd-files in the path, and got the answer in hundreds of a second.

Set vRoot = 'D:\QV\Tester\Files';

Sub NoOfFiles(myPath, myNoOfFiles)
// Count the number of files, meeting creteria, in a path
  Let tNoOfFiles = 0;
For Each File In Filelist ('$(myPath)')
// Count +1 for each file in the path
   Let tNoOfFiles = tNoOfFiles + 1;
Next
Let $(myNoOfFiles) = tNoOfFiles; // Declare the variable and set the value
  Set tNoOfFiles=; // Undeclare
End Sub

// Save the NoOfFiles in variable "vNoOfFiles"
Call NoOfFiles('$(vRoot)\DATA*.qvd', 'vNoOfFiles')