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: 
Not applicable

Use a string array in a function

Hi,

I'm trying to use some strings in an array variable. I want to give this into a function.

I'm getting the error: Error in skript line: Let fileext = 'html','htm'.

The script below works, but with this error.

Is there a way without any errors?

I'm using QlikView 11.20 SR 12.

SET dirpath = ;

SET filescheme = [*A*3];

LET fileext = 'html','htm';

sub workInDirectory (Root,Namescheme,Extlist)

    for each Ext in SubField(Extlist, ',')

    //for each Ext in 'html','htm','qvw' //Works fine, but this is not a variable.

        for each File in FileList (Root & '\' & Namescheme & '.' & Ext)

            if FindOneOf('$(File)', '~$') = 0 then // Protects opening open documents.

                Filelist:

                Load

                    '$(File)'                 as [FilePath],

                    FileSize('$(File)')     as [FileSize],

                    FileTime('$(File)')     as [FileTime]

                    Autogenerate 1;

                   

                Pathinfos:

                LOAD

                    '$(File)'             as [FilePath],

                    FileDir()            as [FileDir],

                    FileName()            as [FileName],

                    FileBaseName()        as [FileBaseName],       

                    FileExtension()     as [FileExtension]

                FROM $(File)

                (fix, codepage is 1252);

            end if

        next File

    next Ext

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

        call workInDirectory (Dir)

    next Dir

end sub

// Call the function.

call workInDirectory ('$(dirpath)','$(filescheme)','$(fileext)')

1 Solution

Accepted Solutions
Not applicable
Author

I've got it. Thx for the help.

SET dirpath = ;

SET filescheme =

  • ;
  • SET fileext = [html htm qvw txt];

    sub workInDirectory(Root, Namescheme, Extlist)

        for i=1 to SubStringCount(Extlist, ' ')

            for each File in FileList(Root & '\' & Namescheme & '.' & SubField(Extlist, ' ', '$(i)'))

                if FindOneOf('$(File)', '~$') = 0 then // Protects opening open documents.

                 

                    Filelist:

                    LOAD

                        '$(File)'              as [FilePath],

                        FileSize('$(File)')    as [FileSize],

                        FileTime('$(File)')    as [FileTime]

                        Autogenerate 1;

                     

                    Pathinfos:

                    LOAD

                        '$(File)'          as [FilePath],

                        FileDir()          as [FileDir],

                        FileName()          as [FileName],

                        FileBaseName()      as [FileBaseName],     

                        FileExtension()        as [FileExtension]

                    FROM $(File)

                    (fix, codepage is 1252);

                 

                end if

            next File

        next i

        for each Dir in DirList(Root&'\*')

            call workInDirectory(Dir, Namescheme, Extlist)

        next Dir

    end sub

    // Call the fuction.

    call workInDirectory('$(dirpath)', '$(filescheme)', '$(fileext)')

    View solution in original post

    4 Replies
    swuehl
    MVP
    MVP

    Try

    SET fileext = 'html','htm';

    But note that the next issue will probably arise here:

    call workInDirectory ('$(dirpath)','$(filescheme)','$(fileext)')

    rubenmarin

    Hi Albert, maybe you can avoid the issue noted by swuehl using another separator and avoiding the use of simple quotes, ie:

    SET v =n1#n2;

    SubField('$(v)', '#')

    Not applicable
    Author

    Thx for the fast answers.

    I changed to SET fileext = [html htm qvw txt];

    But the for each loop only uses the first extension. Maybe my approach is wrong?

    Here is the complete code:

    SET dirpath = ;

    SET filescheme =

  • ;
  • SET fileext = [html htm qvw txt];

    sub workInDirectory(Root,Namescheme,Extlist)

        for each Ext in SubField(Extlist, ' ')

        //for each Ext in 'html','htm','qvw','txt' //Works fine, but this is not a variable.

            for each File in FileList(Root & '\' & Namescheme & '.' & Ext)

                if FindOneOf('$(File)', '~$') = 0 then // Protects opening open documents. (If the count of the sings ~ plus $ is equal zero.)

                   

                    Filelist:

                    Load

                        '$(File)'               as [FilePath],

                        FileSize('$(File)')     as [FileSize],

                        FileTime('$(File)')     as [FileTime]

                        Autogenerate 1;

                       

                    Pathinfos:

                    LOAD

                        '$(File)'           as [FilePath],

                        FileDir()           as [FileDir],

                        FileName()          as [FileName],

                        FileBaseName()      as [FileBaseName],       

                        FileExtension()        as [FileExtension]

                    FROM $(File)

                    (fix, codepage is 1252);

                   

                end if

            next File

        next Ext

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

            call workInDirectory (Dir)

        next Dir

    end sub

    // Call the fuction.

    call workInDirectory('$(dirpath)','$(filescheme)','$(fileext)')

    Not applicable
    Author

    I've got it. Thx for the help.

    SET dirpath = ;

    SET filescheme =

  • ;
  • SET fileext = [html htm qvw txt];

    sub workInDirectory(Root, Namescheme, Extlist)

        for i=1 to SubStringCount(Extlist, ' ')

            for each File in FileList(Root & '\' & Namescheme & '.' & SubField(Extlist, ' ', '$(i)'))

                if FindOneOf('$(File)', '~$') = 0 then // Protects opening open documents.

                 

                    Filelist:

                    LOAD

                        '$(File)'              as [FilePath],

                        FileSize('$(File)')    as [FileSize],

                        FileTime('$(File)')    as [FileTime]

                        Autogenerate 1;

                     

                    Pathinfos:

                    LOAD

                        '$(File)'          as [FilePath],

                        FileDir()          as [FileDir],

                        FileName()          as [FileName],

                        FileBaseName()      as [FileBaseName],     

                        FileExtension()        as [FileExtension]

                    FROM $(File)

                    (fix, codepage is 1252);

                 

                end if

            next File

        next i

        for each Dir in DirList(Root&'\*')

            call workInDirectory(Dir, Namescheme, Extlist)

        next Dir

    end sub

    // Call the fuction.

    call workInDirectory('$(dirpath)', '$(filescheme)', '$(fileext)')