Read files from Directory
Created: 2011-02-03 16:05:02
Last updated: 2011-02-03 16:05:52
This workflow reads files from a given directory, based on a known file extension (e.g. .txt), and then outputs the contents of each file in a single value/single list.
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Titles (1)
Read files from Directory |
Descriptions (1)
This workflow reads files from a given directory, based on a known file extension (e.g. .txt), and then outputs the contents of each file in a single value/single list. |
Dependencies (0)
Inputs (2)
Name |
Description |
input_directory |
|
file_extension |
|
Processors (4)
Name |
Type |
Description |
Read_Text_File |
localworker |
ScriptBufferedReader getReader (String fileUrl) throws IOException {
InputStreamReader reader;
try {
reader = new FileReader(fileUrl);
}
catch (FileNotFoundException e) {
// try a real URL instead
URL url = new URL(fileUrl);
reader = new InputStreamReader (url.openStream());
}
return new BufferedReader(reader);
}
StringBuffer sb = new StringBuffer(4000);
BufferedReader in = getReader(fileurl);
String str;
String lineEnding = System.getProperty("line.separator");
while ((str = in.readLine()) != null) {
sb.append(str);
sb.append(lineEnding);
}
in.close();
filecontents = sb.toString();
|
Flatten_List |
localworker |
Scriptflatten(inputs, outputs, depth) {
for (i = inputs.iterator(); i.hasNext();) {
element = i.next();
if (element instanceof Collection && depth > 0) {
flatten(element, outputs, depth - 1);
} else {
outputs.add(element);
}
}
}
outputlist = new ArrayList();
flatten(inputlist, outputlist, 1); |
Merge_String_List_to_a_String |
localworker |
ScriptString seperatorString = "\n";
if (seperator != void) {
seperatorString = seperator;
}
StringBuffer sb = new StringBuffer();
for (Iterator i = stringlist.iterator(); i.hasNext();) {
String item = (String) i.next();
sb.append(item);
if (i.hasNext()) {
sb.append(seperatorString);
}
}
concatenated = sb.toString();
|
List_Files_by_Extension |
localworker |
Scriptclass FileExtFilter implements FileFilter {
public FileExtFilter(String ext) {
this.ext = ext;
}
public boolean accept(File file) {
return file.getName().endsWith(ext);
}
String ext = null;
}
if (extension == void || extension.equals("")) {
throw new RuntimeException(
"The 'extension' parameter cannot be null. Please enter a valid file extension.");
}
if (directory == void || directory.equals("")) {
throw new RuntimeException(
"The 'directory' parameter cannot be null. Please enter a valid file directory.");
}
File dirObj = new File(directory);
if (!dirObj.exists()) {
throw new RuntimeException("The 'directory' parameter specified:" + directory
+ "does not exist. Please enter a valid file directory.");
}
File[] fileObjList = dirObj.listFiles(new FileExtFilter(extension));
List filelist = new ArrayList();
for (int i = 0; i < fileObjList.length; i++) {
filelist.add(fileObjList[i].getAbsolutePath());
}
|
Outputs (4)
Name |
Description |
flattened_list |
|
merged_list |
|
files_in_dir |
|
file_contents |
|
Datalinks (9)
Source |
Sink |
List_Files_by_Extension:filelist |
Read_Text_File:fileurl |
Read_Text_File:filecontents |
Flatten_List:inputlist |
Read_Text_File:filecontents |
Merge_String_List_to_a_String:stringlist |
input_directory |
List_Files_by_Extension:directory |
file_extension |
List_Files_by_Extension:extension |
Flatten_List:outputlist |
flattened_list |
Merge_String_List_to_a_String:concatenated |
merged_list |
List_Files_by_Extension:filelist |
files_in_dir |
Read_Text_File:filecontents |
file_contents |
Uploader
License
All versions of this Workflow are
licensed under:
Version 1
(of 1)
Credits (1)
(People/Groups)
Attributions (0)
(Workflows/Files)
None
Shared with Groups (0)
None
Featured In Packs (0)
None
Log in to add to one of your Packs
Attributed By (0)
(Workflows/Files)
None
Favourited By (0)
No one
Statistics
Other workflows that use similar services
(0)
There are no workflows in myExperiment that use similar services to this Workflow.
Comments (0)
No comments yet
Log in to make a comment