Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Loading xml files from several folders

Hi,

I have a folderstructure something like this c:\Orders\<Year>\<Monthnumber>\<Daynumber>\ and in every Daynumber folder there are several xml files which all have the same fields.
New folders are automatically created when needed (a new Daynumber folder every day, a new Monthnumber folder everey month and a new Year folder every year)

When loading xml files, two tables are generated.

Example:

MessageLine:
LOAD Key_Field,
    fieldname1,
    fieldname2,
    ....
    fieldname n
FROM (XmlSimple, Table is [Messages/Message/MessageLine]);

Messages:
LOAD Key_Field,
     fieldnameA,
     fieldnameB,
     ......
    
FROM (XmlSimple, Table is [Messages]);

This gives me all the xml files located in C:\Orders\2012\12\01\

But how can I load all the xml files from every Daynumber folders (for all years, months and days)?

1 Solution

Accepted Solutions
Gysbert_Wassenaar

See here for a script to load files from a directory and its subdirectories.


talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar

See here for a script to load files from a directory and its subdirectories.


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks,

made some small modifications, this seems to work for me:

sub ScanFolder(Root)

          for each FileExtension in 'xml'

                    for each FoundFile in filelist( Root & '\*.' & FileExtension)

                              MessageLine:

                              Load

                                        '$(FoundFile)'               as [FilenameWithPath],
                                        '$(FileExtension)'           as [Extension],
                                           other fields....   

                                              .....
                        FROM [$(FoundFile)] (XmlSimple, Table is [Messages/Message/MessageLine]);
                                        
  
                           Messages:
        
                             Load
                                   fields....

                             FROM [$(FoundFile)] (XmlSimple, Table is [Messages]);
 
                    next FoundFile

          next FileExtension

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

                    call ScanFolder(SubDirectory)

          next SubDirectory

end sub

Call ScanFolder('C:\Orders') ;