Vous êtes sur la page 1sur 2

Dynamic folder creation

At times there would be some requirement to create folders dynamically, particularly when the output needs to be split into different files and stored in separate locations.

In this document i am explaining a scenario where there are 10 plant names and we need to create folders for all the 10 plant names to store the corresponding output files. Below is an example table with 10 plant names -

Row_Id 1 2 3 4 5 6 7 8 9 10

Plant_names A B C D E F G H I J

I have to create 10 folders with plant names on it, like A, B, C etc..

You have to declare three global variables - $COUNT (for looping from row_id 1 to 10), $MAX_ROW (to end the loop at max row number) and $PLANT_NAME for capturing the 10 plant names in the loop one by one.

Place a script after the dataflow and insert the below code.

Generated by Jive on 2013-03-20+01:00 1

Dynamic folder creation

$COUNT = 1; # start the count at 1 $MAX_ROW = sql('datastorename','select max(ROW_ID) from tablename'); # capture the rowid in a variable print( $MAX_ROW ); # optional to see the row nos while ( $COUNT <= $MAX_ROW) # initialize the looping begin $PLANT_NAME = sql('datastorename','select PLANT_NAME from tablename where ROW_ID = [$COUNT]'); # selecting plant names one by one print($PLANT_NAME); # optional capture of plant name exec( 'cmd', 'mkdir C:\Users\XYZ\[$PLANT_NAME]',8 ); # create folder using dos command mkdir $COUNT = $COUNT + 1; # looping with counting row id end # end of loop

This will generate 10 folders with names A, B, C etc..

Hope this helps.

Arun

Generated by Jive on 2013-03-20+01:00 2

Vous aimerez peut-être aussi