Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
shannoypaul
Creator
Creator

Program to automate file reading from folders

Folder Table:

FolderName

6709

6683

6893

5567

File Folder Structure would be as follows:


Source

     FolderName

          ORDER-FolderName.csv

          SALES-FolderName.csv

          PARTS-FolderName.csv

          BUYER-FolderName.csv

          REP-FolderName.csv

Example:

Source

     6709

          ORDER-6709.csv

          SALES-6709.csv

          PARTS-6709.csv

          BUYER-6709.csv

          REP-6709.csv

    6683

          ORDER-6709.csv

          SALES-6709.csv

          PARTS-6709.csv

          BUYER-6709.csv

          REP-6709.csv

Source\6709\ORDER-6709.csv

Source\6709\SALES-6709.csv

Source\6709\PARTS-6709.csv

Source\6709\BUYER-6709.csv

Source\6709\REP-6709.csv

I have to write a program to go through all Folders listed in the FolderName Field.

3 Replies
Anil_Babu_Samineni

You can use some thing like below

Load * From Source\6709\*.csv

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
shannoypaul
Creator
Creator
Author

Wildcard will only help me read all files from the folder "6709". I want it to further pick files from subsequent folders i.e. 6683, 6893 and so on.

Since the files would have a standard format I want to use one single Load statement for the entire iteration of folders/files.

Thanks!

Anonymous
Not applicable

I've never tried this but have you tried:

load *

from

Source\*\*.csv;

Otherwise if you have a table of all the folders you can create a loop. 

Something like below.  I haven't tested it but it should work.

FolderTable:

LOAD * INLINE [  

    FolderName

     6709

     6683

     6893

     5567

];

For Each vFolder in FieldValueList('FolderName')

let vFileName = chr(39) & 'Source\' & vFolder & '\*.csv'& chr(39);

 

FileLoads:

Load *

from

$(vFileName)

(txt, codepage is 1252, no labels, delimiter is ',', msq);

Next;