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: 
ajsjoshua
Specialist
Specialist

Loading based on file size

Dear all,

I am trying to load a set of CSV files that we receive every night, however we receive empty 'shells' if no new data has been entered in the system. So what happens is we have 1KB files sitting on the server being ran and causing an error during the load. Other than setting the error mode to zero, I'd like to set up a parameter of: if the file >= 1KB, load, if not, skip.



I tried this script

LET vSize = filesize('lib://CSV/csv_*.csv');


if not IsNull(vSize) then

File:

Load

    book_no,

    receipt_no,

    loan_no,

    cust_name,

    custid,

    cust_branch_code,

    cust_branch_name,

    re_code,

    re_branch_code,

    receipt_date,

    emi,

    "total",

    pay_mode,

    chqno,

    chq_date,

    cancelled,

    cancel_reason,

    FileSize() as filesize,

    cancelled_date

FROM [lib://CSV/csv_*.csv]

(txt, codepage is 28591, embedded labels, delimiter is ',', msq)

where len(cancelled_date)=0

;

end if

STORE File INTO 'lib://QVdata/Transactions.qvd' (qvd); 

drop table File;

exit script;

Regards,

Joshua.

8 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Like this:

For Each vFile in FileList('lib://CSV/csv_*.csv')

    Let vSize = Alt(FileSize(vFile), 0);

   

    If vSize > 1024 Then

   

        ... load from $(vFile)

       

    End If

Next VFile

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
ajsjoshua
Specialist
Specialist
Author

Dear Jonathan,

Thanks for ur reply.

when i try this

For Each vFile in FileList('lib://CSV/csv_*.csv')

    Let vSize = Alt(FileSize(vFile), 0);

If vSize > 1024 Then

File:

Load

    book_no,

    receipt_no,

    loan_no,

    cust_name,

    custid,

    cust_branch_code,

    cust_branch_name,

    re_code,

    re_branch_code,

    receipt_date,

    emi,

    "total",

    pay_mode,

    chqno,

    chq_date,

    cancelled,

    cancel_reason,

    FileSize() as filesize,

    cancelled_date

FROM [lib://CSV/csv_*.csv]

(txt, codepage is 28591, embedded labels, delimiter is ',', msq)

where len(cancelled_date)=0

;

End If

no records are loaded

ajsjoshua
Specialist
Specialist
Author

Dear Jonathan,

PFA for app.

ajsjoshua
Specialist
Specialist
Author

!Dear Jonathan,

PFA for sample data.

I have two csv file

csv_20180801.csv  (file size 1kb)

csv_20180902.csv  (file size 0kb)

I want to load only

csv_20180801.csv

ajsjoshua
Specialist
Specialist
Author

!Dear Jonathan,

PFA for sample data.

I have two csv file

csv_20180801.csv  (file size 1kb)

csv_20180902.csv  (file size 0kb)

I want to load only

csv_20180801.csv

jonathandienst
Partner - Champion III
Partner - Champion III

Well the sample will only load files with a size greater than 1024 bytes because

>> I'd like to set up a parameter of: if the file >= 1KB, load, if not, skip.


But csv_20180801.csv is only 400 bytes, so based on your original post, it should not be loaded.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
ajsjoshua
Specialist
Specialist
Author

Dear Jonathan,

Actually i have some other files of size 13kb,9kb like still its also not loading.

Regards,

Joshua.

jonathandienst
Partner - Champion III
Partner - Champion III

I suggest that you post the script you are trying so that we can see where you went wrong.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein