Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
Save the Date: QlikWorld Online, June 24-25, 2020. Free global virtual event for data integration and data analytic gurus. Register Today
Highlighted
Valued Contributor

creation folder with loop

I need to loop a table (as for example for each), I have to store the name of the files in a table and I need to create folders with file names;

sub DoDir (Root)

   for each Ext in  'qvd'

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

      set v=FilePath();

        LOAD

           

            '$(File)' as Name,

            FileSize( '$(File)' ) as Size,

            FileTime( '$(File)' ) as FileTime,

            Mid('$(File)',21) as dossierecap,

            Mid(Mid('$(File)',21),index(Mid('$(File)',21),'\')+1 ) as namefile,

             mid(Mid('$(File)',21),Len('DONNEES_RECAP')+1,3 )as Month

          

           autogenerate 1;

      next File

   next Ext

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

      call DoDir (Dir)

     

   next Dir

end sub

call DoDir ('C:\pfe\qlikview\qvd');

So I have to create the files under name 'C:\pfe\qlikview\qvd' & namefile & Month

6 Replies
Highlighted

Re: creation folder with loop

May be create again two more for each loop for name and month then use same in File to extend and club

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
Highlighted
Valued Contributor

Re: creation folder with loop

i have to use the cmd

Execute cmd.exe /C mkdir C:\pfe\qlikview\qvd & namefile & Month;

with this script i cant

Highlighted
Partner
Partner

Re: creation folder with loop

In the Tools/EditModule Script create a function

================================

Function CreateDir(strDirectory)

  Set objFSO = CreateObject("Scripting.FileSystemObject")

  Set objFolder = objFSO.CreateFolder(strDirectory)

End Function

In the load Script

================================

Let Create= CreateDir('c:\CreateDir');

Highlighted
Valued Contributor

Re: creation folder with loop

Good Morning Piet,

I understood the first part, that the function Create Dir is used to create a folder by the strDirectory path, but still I do not understand how to put the function in load script

Highlighted

Re: creation folder with loop

Hi Souad,

Your requirement is not clear enough. Try this and let me know. If this is not you want please elaborate your requirement a bit.

Sub DoDir (Root)
for each Ext in  'qvd'
for each File in filelist (Root&'\*.' &Ext)
set vPath = 'C:\pfe\qlikview\qvd';

Data:
LOAD
'$(File)'
as Name,
FileSize( '$(File)' ) as Size,
FileTime( '$(File)' ) as FileTime,
Mid('$(File)',21) as dossierecap,
Mid(Mid('$(File)',21),index(Mid('$(File)',21),'\')+1 ) as namefile,
mid(Mid('$(File)',21),Len('DONNEES_RECAP')+1,3 )as Month
autogenerate 1;

next File
next Ext

//================================================================
Let vnamefile = Peek('namefile');
Let vMonth = Peek('Month');
Execute cmd.exe /C mkdir $(vPath)\$(vnamefile)$(vMonth) ;

Store Data into $(vPath)\$(vnamefile)$(vMonth)\$(vnamefile).qvd (qvd);
DROP Table Data;
//================================================================
 
If Not  $(vPath)\$(vnamefile)$(vMonth) then

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

next Dir
End If

end sub
call DoDir ('C:\pfe\qlikview\qvd');

Highlighted
Partner
Partner

Re: creation folder with loop

The function is not in the load script but in the macro editor, from the qlikview menu Tools/Edit module

Tools_EditModule.png

EditModule.png

And then in the load script

CreateLoadScript.png