List files by regex - several answers
Created: 2010-10-28 15:32:39
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 and the file paths matching the regular expression '.*i.*', i.e. those containing an 'i', are output.
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Titles (2)
List files by regex - several answers |
List files by regex - several matches |
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 and the file paths matching the regular expression '.*i.*', i.e. those containing an 'i', are output. |
Dependencies (0)
Processors (4)
Name |
Type |
Description |
create_temporary_directory |
beanshell |
ScriptFile temp = File.createTempFile("taverna", ".dir");
temp.delete();
temp.mkdir();
temp.deleteOnExit();
directoryPath = temp.getCanonicalPath(); |
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"); |
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_including_i |
stringconstant |
Value.*i.* |
Beanshells (2)
Name |
Description |
Inputs |
Outputs |
create_temporary_directory |
|
|
directoryPath
|
populate_directory |
|
directory
|
|
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_including_i: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