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: 
Fred-Zabala
Contributor II
Contributor II

How to skip script if directory is empty

Hi All

 

I am currently scanning a directory for certain files. How do i skip the rest of the script if it doesn't find any of the following files? Please see below for script. So if it cannot find anything in the (Lease File List), i want it to ignore the call for Documentlist_leases and skip to //SubFileLIst

// Lease file list
sub DoDir (Root)
for each Ext in 'txt', 'xlsx', 'docx', 'pdf', 'msg'

for each File in filelist (Root&'\*.' &Ext)

DocumentsList_Leases:
LOAD
'$(File)' as LeasefullPath,
SubField('$(File)', '\', 6) as PML_SEQ, //return everything after the 5th '\'
Right( '$(File)', Len( '$(File)') - FindOneOf( '$(File)', '\', 6) ) as LeaseFileName
autogenerate 1;

next File

next Ext

for each Dir in dirlist (Root&'\*' )
call DoDir (Dir)
next Dir

end sub

call DoDir ('\\AKL-SQL01.anz.corp.local\IIS_$(vClient)\F_Pm_Lease\')
Call StoreAndDrop('DocumentsList_Leases');

//Sublease file list
sub DoDir (Root)
for each Ext in 'txt', 'xlsx', 'docx', 'pdf'

for each File in filelist (Root&'\*.' &Ext)

DocumentsList_Subleases:
LOAD
'$(File)' as SubleasefullPath,
SubField('$(File)', '\', 6) as F_Pm_Sublease_SEQ, //return everything after the 5th '\'
Right( '$(File)', Len( '$(File)') - FindOneOf( '$(File)', '\', 6) ) as SubleaseFileName
autogenerate 1;

next File

next Ext

for each Dir in dirlist (Root&'\*' )
call DoDir (Dir)
next Dir

end sub

call DoDir ('\\AKL-SQL01.anz.corp.local\IIS_$(vClient)\F_Pm_Sublease\');
Call StoreAndDrop('DocumentsList_Subleases');

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

If NoOfRows('DocumentsList_Subleases') > 0 Then

  Call StoreAndDrop('DocumentsList_Subleases');

EndIf

-Rob

View solution in original post

7 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

If NoOfRows('DocumentsList_Subleases') > 0 Then

  Call StoreAndDrop('DocumentsList_Subleases');

EndIf

-Rob

Fred-Zabala
Contributor II
Contributor II
Author

Thank you! This works a treat!

Fred-Zabala
Contributor II
Contributor II
Author

Hey

Another question. We've pulled massive files from our network already, and its good to re-run the script every now and then so that it gets the latest files. But is there a way to skip files which we already have pulled into the qvd? LIke a skip for it, and only pull the latest ones?

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Just to clarify. You are not actually loading data from those files, you are just building a list of filenames, correct?

-Rob

Fred-Zabala
Contributor II
Contributor II
Author

Yep. Not loading, building a list of filenames.

Basically, filenames will be put into a table, which will create links to said filename. That's all, pulling data from the files themselves

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I can't think of ways to "skip" files that would be any faster than what you are doing. Unless your directories are by date and you could skip entire directories. 

-Rob

Fred-Zabala
Contributor II
Contributor II
Author

Unfortunately, all our files our files are not by dates but by actual document name.

I'll see if we can do something about the naming, but thanks for the help on the rest 🙂