6 Replies Latest reply: Apr 21, 2017 6:23 AM by Piet Hein van der Stigchel RSS

    creation folder with loop

    souad ouertani

      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

        • Re: creation folder with loop
          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

          • Re: creation folder with loop
            Tamil Nagaraj

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