Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
Not applicable

How to check if a QVD file exists when it's name isn't fixed?

As part of my incremental load process, I am loading in a number of smaller QVD files into other QVD files.

The small files are created with a date string on the end of the filename.

before attempting to load the small files, I would like to check to see if any exist, so it can fail gracefully.

The examples I have found use the QvdCreateTime() function to check if a QVD file exists, but this needs a specific filename passed in.

Does anyone have a way of checking to see if any files exist when the filename is not fixed.

ie a file created today at midday would be  TABLENAME_20150619120000.qvd

Thanks

Mark

1 Solution

Accepted Solutions
MVP
MVP

Re: How to check if a QVD file exists when it's name isn't fixed?

    let vFileExists = 0;

    For each File in ('$(vDataPath)$(vTableName)_*.qvd')

        let vFileExists = 1;

        exit for when $(vFileExists) = 1;

    NEXT File

You are missing the filelist() here:

  For each File in FileList('$(vDataPath)$(vTableName)_*.qvd')

9 Replies
Partner
Partner

Re: How to check if a QVD file exists when it's name isn't fixed?

if you use a for loop like the one bellow, neither if it exists nor the name matters :

FOR EACH File in FileList('yourshare\*.qvd')

MVP
MVP

Re: How to check if a QVD file exists when it's name isn't fixed?

You can use something like

Let vQVDExist = 0;

For each File in Filelist('TABLENAME_*.qvd')

    

Let vQVDExist = 1;

Next File

ramoncova06
Valued Contributor III

Re: How to check if a QVD file exists when it's name isn't fixed?

the problem with using a "*" when reading files is that this will give you all files that exist in that folder for that table name,

so unless you move the qvd's after you process them you will keep adding them in.


Going back to the qvdcreatetime, you are able to add to a dynamic file name


let vQVDTime = Now()


let vControlQVD = 'TABLENAME_$(vQVDTime ).qvd';

let vControlQVDPathCreationDate =  filetime( '$(vControlQVD)' );

if len('$(vControlQVDPathCreationDate)') >  0 then

whatever you want to do

end

Not applicable

Re: How to check if a QVD file exists when it's name isn't fixed?

Thanks for the replies,

to clarify the question a little bit - all I need is establish if a file of type TABLENAME_*.qvd exists before using the LOAD * from TABLENAME_*.qvd syntax.

Using a hybrid of the answers above, I came up with:

// Check there are some files to load...

    let vFileExists = 0;

    For each File in ('$(vDataPath)$(vTableName)_*.qvd')

        let vFileExists = 1;

        exit for when $(vFileExists) = 1;

    NEXT File

       

    if $(vFileExists) = 1 then

        LOAD * from $(vDataPath)$(vTableName)_*.qvd;

    else

         TRACE No Files to Load;

    end if;

However, this does not seems to work. Does the For loop always execute? I would have thought it would only enter the body of the loop if the filelist had some files in?

Thanks

Mark

Partner
Partner

Re: How to check if a QVD file exists when it's name isn't fixed?

Hi,

Try doing something like this

IF(FileSize(FileSource\TABLENAME_20150619120000.qvd) )> 0 THEN

     Do whatever you want when the file exist

else

     Do whatever you want if the file doesn't exist..

   ENDIF

Not applicable

Re: How to check if a QVD file exists when it's name isn't fixed?

Hi Thanks for the suggestion.

I am indeed moving processed files into a separate folder later on in the load script, so * is safe enough at this point.

It is very unlikely that a file will have been created for exactly the time that I am running this aspect of the script. ie that a TABLENAME_now().qvd will exist

All I need to do is check that something in the format TABLENAME*.qvd exists ready to be loaded.

Thanks

Mark

MVP
MVP

Re: How to check if a QVD file exists when it's name isn't fixed?

    let vFileExists = 0;

    For each File in ('$(vDataPath)$(vTableName)_*.qvd')

        let vFileExists = 1;

        exit for when $(vFileExists) = 1;

    NEXT File

You are missing the filelist() here:

  For each File in FileList('$(vDataPath)$(vTableName)_*.qvd')

Not applicable

Re: How to check if a QVD file exists when it's name isn't fixed?

OK, it appears I had missed the filelist mask within the For loop definition....

So it works using:

For each File in filelist ('$(vDataPath)$(vTableName)_*.qvd')

Thanks

Mark

deborahs
New Contributor III

Re: How to check if a QVD file exists when it's name isn't fixed?

Hello sir, I am an intern working on a project where I'm facing a similar issue. My objective is to check whether the file was created before 6.15 am of the current date and notify (trigger an email on nprint) the concerned person if it hasn't. I'm trying to use something similar and I'm inserting a where clause but i still can't figure it out! Any help would be appreciated! Thanks in advance!!! 🙂