Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

martynlloyd
Contributor III

File functions not working

Hi,

I have this script below, FileSize and FileTime are returning data, but FilePath, FileDir, FileExtension are not returning anything - what is wrong?

sub
DoDir (Root)
for each Ext in 'bmp', 'jpg', 'png', 'tif'

for each File in filelist (Root&'\*.' &Ext)
LOAD
'$(File)'
as [Image Name],
FilePath('$(File)') as [Image Path],
FileDir('$(File)') as [Image Dir],
FileExtension('$(File)') as [Image Ext],
FileSize('$(File)') as [Image Size],
FileTime('$(File)') as [Image Time],
Year(Date(FileTime('$(File)'))) as [Year]

autogenerate 1;

next File
 
next Ext

for each Dir in dirlist (Root&'\*' )
call DoDir (Dir)
next Dir

end sub

Tags (1)
1 Solution

Accepted Solutions
MVP & Luminary
MVP & Luminary

Re: File functions not working

If I look closer on your example I see now that you didn't load from a file else per autogenerate and therefore you couldn't use those file-functions. Instead of them use:

...

'$(File)' as [Image Path],

subfield('$(File)', '.', 2) as [Image Ext],

mid('$(File)', 1, index('$(File)', '\', -1) - 1) as [Image Dir]

...

- Marcus

6 Replies
sasikanth
Valued Contributor III

Re: File functions not working

May be this

sub

DoDir (Root)
for each Ext in 'bmp', 'jpg', 'png', 'tif'

for each File in filelist (Root&'\*.' &$(Ext))


LOAD
'$(File)'
as [Image Name],
FilePath('$(File)') as [Image Path],
FileDir('$(File)') as [Image Dir],
FileExtension('$(File)') as [Image Ext],
FileSize('$(File)') as [Image Size],
FileTime('$(File)') as [Image Time],
Year(Date(FileTime('$(File)'))) as [Year]

autogenerate 1;

next File
 
next Ext

for each Dir in dirlist (Root&'\*' )
call DoDir (Dir)
next Dir

end sub

MVP & Luminary
MVP & Luminary

Re: File functions not working

You need to use these functions without a parameter like:

filepath() as [Image Path]

Another way to get these informations could be to use string-functions like subfield() or '$(EXT)' for the file-extension.

- Marcus

martynlloyd
Contributor III

Re: File functions not working

Marcus,

I tried that first, that doesn't work either.

Regards,

Marty.

MVP & Luminary
MVP & Luminary

Re: File functions not working

If I look closer on your example I see now that you didn't load from a file else per autogenerate and therefore you couldn't use those file-functions. Instead of them use:

...

'$(File)' as [Image Path],

subfield('$(File)', '.', 2) as [Image Ext],

mid('$(File)', 1, index('$(File)', '\', -1) - 1) as [Image Dir]

...

- Marcus

martynlloyd
Contributor III

Re: File functions not working

Thanks Marcus ,

But how come the FileSize and FileTime worked?

Regards,

Marty.

MVP & Luminary
MVP & Luminary

Re: File functions not working

No, I meant only those file-functions which didn't work - by filetime() and filesize() you could further use your previous and working approach.

- Marcus