List files by regex - no matches
Created: 2010-10-28 15:30:54
The create_temporary_directory beanshell creates a temporary directory and outputs the path to that directory.
The populate_directory beanshell creates several files within the temporary directory.
Once the directory has been populated, it is examined by the List_files_by_regex service. Since no files match the regular expression 'x.*' i.e. no files have a name that starts with 'x', an empty list is output.
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Titles (2)
List files by regex - no matches |
List files by regex - no answer |
Descriptions (1)
The create_temporary_directory beanshell creates a temporary directory and outputs the path to that directory.
The populate_directory beanshell creates several files within the temporary directory.
Once the directory has been populated, it is examined by the List_files_by_regex service. Since no files match the regular expression 'x.*' i.e. no files have a name that starts with 'x', an empty list is output. |
Dependencies (0)
Processors (4)
Name |
Type |
Description |
populate_directory |
beanshell |
Scriptcreatefile(directory, filename) {
File f = new File(directory, filename);
f.createNewFile();
}
createfile(directory, "alan.txt");
createfile(directory, "stian.txt");
createfile(directory, "jits.txt");
createfile(directory, "sergejs.bin");
createfile(directory, "carole.png");
createfile(directory, "david.png");
createfile(directory, "stuart.txt");
createfile(directory, "ian.png"); |
create_temporary_directory |
beanshell |
ScriptFile temp = File.createTempFile("taverna", ".dir");
temp.delete();
temp.mkdir();
temp.deleteOnExit();
directoryPath = temp.getCanonicalPath(); |
List_Files_By_Regex |
localworker |
Scriptclass FileRegexFilter implements FileFilter {
public FileRegexFilter(String regex) {
this.regex = regex;
}
public boolean accept(File file) {
return file.getName().matches(regex);
}
String regex = null;
}
if (regex == void || regex.equals("")) {
throw new RuntimeException(
"The 'regex' 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 FileRegexFilter(regex));
List filelist = new ArrayList();
for (int i = 0; i < fileObjList.length; i++) {
filelist.add(fileObjList[i].getAbsolutePath());
}
|
strings_starting_with_x |
stringconstant |
Valuex.* |
Beanshells (2)
Name |
Description |
Inputs |
Outputs |
populate_directory |
|
directory
|
|
create_temporary_directory |
|
|
directoryPath
|
Outputs (1)
Name |
Description |
matching_files |
|
Datalinks (4)
Source |
Sink |
create_temporary_directory:directoryPath |
populate_directory:directory |
create_temporary_directory:directoryPath |
List_Files_By_Regex:directory |
strings_starting_with_x:value |
List_Files_By_Regex:regex |
List_Files_By_Regex:filelist |
matching_files |
Coordinations (1)
Controller |
Target |
populate_directory |
List_Files_By_Regex |
Uploader
License
All versions of this Workflow are
licensed under:
Version 1
(of 1)
Credits (0)
(People/Groups)
None
Attributions (0)
(Workflows/Files)
None
Shared with Groups (1)
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