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: 
djbloiss
Contributor III
Contributor III

Crash on Next SubDirectory

I need to be able to loop through the directory '\\FILESVR1\FinalDailyDispatchSheet$\' and all subdirectories under it, to load all .xls files.  It works for the main directory but will not find the subdirectories.  It is crashing on the next subdirectory statement.  What am I doing wrong?

Here is my code (with the unnecessary pieces taken out):

DIRECTORY \\FILESVR1\FinalDailyDispatchSheet$\;

for Each subDirectory in DirList(Dir & '*')

    for Each file in FileList('*.xls')

        DeliveryData:

        LOAD

             @1 as Run,

             @2 as [Description],

             @3 as [Stops],

             @4 as [Pieces]

        FROM [$(file)]

        (biff, no labels, table is Table1)

        ;

    next file

NEXT SubDirectory

;

3 Replies
andrey_krylov
Specialist
Specialist

Hi Daniel. I've marked the errors. But it loops only subdirs and no root


DIRECTORY \\FILESVR1\FinalDailyDispatchSheet$\;

for Each subDirectory in DirList(Dir & '*')

    for Each file in FileList(subDirectory  & '\*.xls')

        DeliveryData:

        LOAD

            @1 as Run,

            @2 as [Description],

            @3 as [Stops],

            @4 as [Pieces]

        FROM [$(file)]

        (biff, no labels, table is Table1)

        ;

    next file

NEXT subDirectory

;

andrey_krylov
Specialist
Specialist

Or try this SUB

SUB LoadFiles(Root)

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

     LOAD msgbox('$(FoundFile)') AutoGenerate 1;

  next FoundFile

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

       call LoadFiles(SubDirectory)

  next SubDirectory

ENDSUB