Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
tejaswinisunkar1
New Contributor II

To check if file exists amd to check if data is in file or not


Hi,

I have to check if x.csv,y.csv.z.csv etc.. files were present in a path and also have to check if there is any data present in that file.

if file not existed nor daat is not present in any of the file i should throw a message that data or file is not available

3 Replies
Employee
Employee

Re: To check if file exists amd to check if data is in file or not

You could use the FileSize function to check the file, FileSize(filename).

If the file does not exist it returns Null, if it is empty it returns 0.

Re: To check if file exists amd to check if data is in file or not

An alternative is to use a For - Next loop, like

For each vFile in FileList('c:\<path>\*.csv')

     Load *,

          '$(vFile)' as FileName,

          RecNo() as RecordNo

          From "$(vFile)" ... ;

Next vFile

This will loop over all files that match the mask. By looking at FileName and RecordNo you can see where you have your data. It will however not throw any messages...

See also Find My Files.zip

HIC

Employee
Employee

Re: To check if file exists amd to check if data is in file or not

Do you have a list of files that you want to check?

If you run this, with the first inline load substituted with a load of your file list, you will get a table of each file and the file status.

FileStatus will be 'Missing' if file does not exist, 'Empty' if it's zero-length or 'OK' otherwise.

You won't get any messages, but you could use this table for example to load only OK files (WHERE FileStatus = 'OK') or to show a table with not OK files.

files:

LOAD * INLINE [

    file

    C:\filepath\exists.csv

    C:\filepath\empty.csv

    C:\filepath\doesnotexist.csv

];

For each vFile in FieldValueList('file')

     FileList:

     Load

       '$(vFile)' as FileName,

        If(IsNull(FileSize('$(vFile)')),'Missing',If(FileSize('$(vFile)')=0,'Empty','OK')) As FileStatus

     AutoGenerate 1;

Next vFile

Drop table files;