I have a single text file with 50 lines of text
Code: Select all
line1
line2
line3
...
Code: Select all
line1.txt
line2.txt
line3.txt
...
Is it possible to modify it to output text files instead?
Code: Select all
// Helper function
var forEach = function(array, callback){
var currentValue, index;
for (i = 0; i < array.length; i += 1) {
if(typeof array[i] == "undefined"){
currentValue = null;
} else {
currentValue = array[i];
}
index = i;
callback(currentValue, i, array);
}
}
// Construct File object
var file = new File( job.getPath() );
/// Open file as read only
file.open( File.ReadOnly );
// Create an array of the lines of the file
var file_as_array = file.readLines();
// Close the file
file.close();
// Get the first line
// var first_line = file_as_array[0]; // This is how you get the first line if you need it
// Slice the array without the first line
var sliced_array = file_as_array.slice(1, (file_as_array.length-1));
// Below this line is all psuedo code
var new_file_string;
forEach(sliced_array, function(line, index){
new_file_string += line + "\n"; // Add each line to the string, one by one
});
var new_path = job.createPathWithName("whatever.txt");
File.write(new_path, new_file_string, "UTF-8");
// Send job to next flow element
job.sendToSingle( new_path );