Qlik Community

QlikView Documents

Documents for QlikView related information.

Loop through Folders and sub folders to get file names

MVP
MVP

Loop through Folders and sub folders to get file names

 

Hi All,

The below script gets and stored all the Qlikview filenames in folder and subfolders.

Set vConcatenate = ;

FileList:
LOAD
'' AS SourceFile
AUTOGENERATE 0;

sub ScanFolder(Root)

          for each FileExtension in 'qvw'

                    for each FoundFile in filelist( Root & '\*.' & FileExtension)

                              FileList:
                              LOAD '$(FoundFile)' as SourceFile
       AUTOGENERATE 1;
                             

                              Set vConcatenate = Concatenate;

                    next FoundFile

          next FileExtension

          for each SubDirectory in dirlist( Root & '\*' )

                    call ScanFolder(SubDirectory)

          next SubDirectory

end sub


Call ScanFolder('C:\Jagan\QV Dashboards\QV Production Dashboards') ;

Hope it helps others.

Regards,

Jagan.

Tags (2)
Labels (1)
Comments
hectorgarcia
Contributor III

what if you need to iterate in several calls??

is it possible to create the calls dinamically?

MVP
MVP

Just

Call this function like this

Call ScanFolder(YourFilePath) ;

Regards,

Jagan.

jason_michaelid
Honored Contributor II

Thanks Jagan - very useful.  I have extended it slightly to allow passing of a file mask and output string name which some people might find useful.

Jason

/************************************************************

Create subroutine for list all file of a particular mask

in a specified folder. Will output a comma-delimited list of

all files in folder matching the given mask into a named variable

Usage e.g. :

CALL ScanFolder('$(vFilePath)','ABC*.xlsx','vMyFiles');

************************************************************/

  SUB ScanFolder(Folder,Mask,OutputVariable)

  FOR EACH FoundFile in FileList(Folder & Mask)

  FileList:

  LOAD

  SubField('$(FoundFile)','\',-1) AS FileName

  AutoGenerate 1;

  NEXT FoundFile

  IF NoOfRows('FileList') > 0 THEN

  Variable:

  LOAD

  Concat(Chr(39) & FileName & Chr(39),',') AS $(OutputVariable)

  RESIDENT FileList;

  LET $(OutputVariable) = Peek('$(OutputVariable)');

  DROP TABLES FileList,Variable;

  ENDIF;

  ENDSUB;

/***********************************************************/

Note:  I have removed the subfolder scanning as I did not require it.

LidiaVonk
New Contributor

Hi Jagan,

Why the vConcatenate ??

tnx Lidia

Version history
Revision #:
1 of 1
Last update:
‎08-07-2013 03:04 AM
Updated by: