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: 
martynlloyd
Partner - Creator III
Partner - Creator 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

1 Solution

Accepted Solutions
marcus_sommer

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

View solution in original post

6 Replies
sasikanth
Master
Master

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

marcus_sommer

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
Partner - Creator III
Partner - Creator III
Author

Marcus,

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

Regards,

Marty.

marcus_sommer

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
Partner - Creator III
Partner - Creator III
Author

Thanks Marcus ,

But how come the FileSize and FileTime worked?

Regards,

Marty.

marcus_sommer

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