Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
;
Take a look here: https://help.qlik.com/en-US/sense/June2018/Subsystems/Hub/Content/Scripting/ScriptControlStatements/...
- Marcus
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
;
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