Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Support Case Portal has moved to Qlik Community! Read the FAQs to start exploring Support resources.
cancel
Showing results for 
Search instead for 
Did you mean: 
kdmarkee
Specialist
Specialist

Loop through a set of files to find the good vs corrupt ones

I have and NPrinting job that generates several pdf files and delivers them to a folder.  Once in a blue moon a pdf will have "_[FAILED]_" in the file name and the pdf is basically corrupt and won't open.

If it is possible, I'd like some scripting help on how I could loop through this set of files and 

1) find the ones that are not "failed" (this I have figured out)

2) find the ones that are "failed" (I cannot seem to get this work because the file functions don't seem to execute on a corrupt pdf file)

Then once I have this info, I can leverage it in an NPrinting report that I will email myself as a means of notification that I need to address that pdf (which entails running my report for that particular pdf scenario via On Demand so I will have a successful pdf to replace the failed one).

Thanks.

4 Replies
marcus_sommer
MVP & Luminary
MVP & Luminary

Maybe with something like this:

for each file in filelist('Path\File*.pdf')
   if wildmatch('$(file)', '*_[FAILED]_*') then
      ...
   end if
next

- Marcus

kdmarkee
Specialist
Specialist
Author

I think my issue was that it did not like it when I used "from '$(file)'" in my IF test to build a table.  I guess if it is corrupt maybe it cannot be used as a source to load from.

marcus_sommer
MVP & Luminary
MVP & Luminary

Loading from a pdf-file isn't possible because it's not a data-file. Further your logic may miss appropriate brackets around the path in the case that there any spaces or other special chars - means something like: [$(file)]. In the case that there are various file-types included from your file-pattern you need to consider it within the file-format statement.

- Marcus

QFabian
Specialist II
Specialist II

Another way can be put this inside the for next :

Load

'$(file)'  as File,

findoneof('$(file)', '_[FAILED]_')  as FileFlag

Autogenerate(1);

 

So if the flag is >0, is a corrupted file.

QFabian