Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Ralf-Narfeldt
Employee
Employee

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.

hic
Former Employee
Former Employee

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

Ralf-Narfeldt
Employee
Employee

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;