Showing results for 
Search instead for 
Did you mean: 

Text file to csv files (Many to Many) from folder

New Contributor

Dear Experts,

I'm trying to read text files from a folder and i need to create csv file in target file location. For Example:

i have 3 .txt files in a source folder and i need to create 3 .csv files in target folder. I have tried below approach but it's failing:

Directory Browser->ForEach->FileReader->CSVParser->Mapping->CSVFormatter->FileWritter.

Also i need to name the 3 different target filenames with dateformat EX: sourcefilename_yyyyMMddHHmmss.csv

Please let me know if anyone succeeded, Please share your experience or thoughts which will help me.

Thanks in advance



New Contributor III

Normally it should work in the fashion you describe, i have never used the ForEach. But try to create a child pipeline which will be executed by a pipeline execute snap and get the source file path from the Directory browser or a file poller snap.
First pipeline would be a Directory browser -> Pipeline execute
Second pipeline would be File reader -> CSV Parser (if this is what you need) -> Mapping -> CSV formatter -> File writer

Easiest way is that you construct and send the target filename as a pipeline parameter to the second pipeline, this way you can access it from the file writer snap easily via expression _target_filename for example
Make sure to set the batch size to 1 for the pipeline execute snap, it will execute the pipeline once for each file.

Suggestion on how to construct the target filename:



$Path.match(/\/([^\/]*?)\.[^\/]*$/)[1] + "_" +{"format":"yyyyMMddHHmmss"}) + ".csv"