1 Reply Latest reply: Aug 30, 2015 6:15 PM by Stefan Wühl RSS

    Selecting all files in a folder

    Mark Graham

      Hi all,

       

      Hope everyone is doing good.

       

      I'm working on a requirement where i have multiple folders, Say

      C:\QVDATA\Folder1;

      C:\QVDATA\Folder2,and

      C:\QVDATA\Folder3;

      I wanna navigate to every folder and select all the files with ".XLS" extension.

      I tried using For loop but not getting executed.

       

      Can someone throw some limelight ..

      Thanks in Advance.

        • Re: Selecting all files in a folder
          Stefan Wühl

          You can use a For Each file In FileList() loop for that, there is even an example in the HELP that does pretty much what you want:

           

          // list all QV related files on disk

          SUB DoDir (Root)

          FOR Each Ext in 'qvw', 'qva', 'qvo', 'qvs'

          FOR Each File in filelist (Root&' \*.' &Ext)

          LOAD

          '$(File)' as Name,

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

          FileTime( '$(File)' ) as FileTime

          autogenerate 1;

          NEXT File

          NEXT Ext

          FOR Each Dir in dirlist (Root&' \*' )

          call DoDir (Dir)

          NEXT Dir

          ENDSUB

          CALL DoDir ('C:')

           

          If you want to read xls files, use the appropriate extensions in the filelist (...in 'xls', 'xlsx') and create an appropriate LOAD statement in the loop body.