Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
chiru_thota
Specialist
Specialist

Issue with FileSize() function?

Hi All,

I am using FileSize() function to get the size of our QVW's and it is working fine.

I have 10 QVW's.Some how for 3 QVW's I am not getting any size when I use

load FileSize() as FS from QVWNAME.QVW. I am not getting any error also.

It is weird.Any QVW internal setting causing this issue ?

Thanks,

Chiru.

1 Solution

Accepted Solutions
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Chiranjeevi,

If the files really are all over the place then you could use an inline load to list the files, and then loop around to get the sizes.  The code would be:

Temp_Files:

LOAD

     FileName

INLINE [

FileName

..\..\..\File1.qvw

..\..\File2.qvw

];


for i = 0 to NoOfRows('Temp_Files') -1

     let vFile = Peek('FileName', i, 'Temp_Files');

     let vFileSize = Alt(FileSize('$(vFile)'), 0);

     FileSize:

       LOAD

          '$(vFile)' as FileName,

          $(vFileSize) as FileSize

     AUTOGENERATE(1)

     ;

next


DROP TABLE Temp_Files;

I was surprised when you said the technique of loading it in the way you described worked for all but three QVW files.  I tried it on a couple and it didn't work on any of them.  As Rob says this approach will give you no problems.

Steve

View solution in original post

7 Replies
Not applicable

Try to load with NoConcatenate statement.

ex. in the load script:

NoConcatenate Load FileSize() as...

Hope this helps.

MC

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi there,

I am surprised it is working at all with a load from a QVW.  Is it that you are loading from some QVD's and these are working but the QVW's are not?

If you want to get the size of a number of files I would go for something like this:

for each vFile in FileList('.\*.qv*')

     let vFileSize = Alt(FileSize('$(vFile)'), 0);

     FileSize:

       LOAD

          '$(vFile)' as FileName,

          $(vFileSize) as FileSize

     AUTOGENERATE(1)

     ;

next

There are a whole bunch of functions that you can run over QVD files that will give you more information about them.

You will find that code will give you the full path to the file in the FileName field.  You can either do a Replace function to remove the path, or a mid function based on an index on the last backslash.

Hope that helps,

Steve

chiru_thota
Specialist
Specialist
Author

Hi Steve,

No I am not loading from QVD...I want the size of ABC.QVW.

I am writing statement for all my QVW's as there in different folders.One load for each.

Load FileSize() as Size_QVW

FROM ..\..\..\..\..\ABC.qvw

Those statement working fine and fecthing me size except 3 QVW's.

Thanks,

Chiru

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

This is not really a good way to use filesize(). You are actually LOADing a QVW, which will have mixed results depending on what filespec parameters you use and what the file actually contains. Steve's recommendation to use the filesize(path) function would be reliable.

-Rob

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Chiranjeevi,

If the files really are all over the place then you could use an inline load to list the files, and then loop around to get the sizes.  The code would be:

Temp_Files:

LOAD

     FileName

INLINE [

FileName

..\..\..\File1.qvw

..\..\File2.qvw

];


for i = 0 to NoOfRows('Temp_Files') -1

     let vFile = Peek('FileName', i, 'Temp_Files');

     let vFileSize = Alt(FileSize('$(vFile)'), 0);

     FileSize:

       LOAD

          '$(vFile)' as FileName,

          $(vFileSize) as FileSize

     AUTOGENERATE(1)

     ;

next


DROP TABLE Temp_Files;

I was surprised when you said the technique of loading it in the way you described worked for all but three QVW files.  I tried it on a couple and it didn't work on any of them.  As Rob says this approach will give you no problems.

Steve

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Or you can simplify your life by using Qlikview Components:

SUB MyFileSub (filepath)

  MyFiles:

  LOAD

  '$(filepath)' as [FilePath],

  FileTime('$(filepath)') as [FileTime],

  FileSize('$(filepath)') as [FileSize]

  AutoGenerate 1

  ;

END SUB

CALL Qvc.ListFiles('C:\dir1', '*.qvw', -1, 'MyFileSub');

CALL Qvc.ListFiles('C:\dir2', '*.qvw', -1, 'MyFileSub');

CALL Qvc.ListFiles('C:\dir3', '*.qvw', -1, 'MyFileSub');

-Rob

chiru_thota
Specialist
Specialist
Author

Thanks a lot  Steve&Rob.

New code is easy and working perfect.