Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
souadouert
Specialist
Specialist

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
Anil_Babu_Samineni

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

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
souadouert
Specialist
Specialist
Author

i have to use the cmd

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

with this script i cant

stigchel
Partner - Master
Partner - Master

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');

souadouert
Specialist
Specialist
Author

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

tamilarasu
Champion
Champion

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');

stigchel
Partner - Master
Partner - Master

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