 |
hiteksoftware.com User discussion forum
|
View previous topic :: View next topic |
Author |
Message |
melvin Site Admin
Joined: 25 May 2006 Posts: 635 Location: Santa Barbara, california
|
Posted: Sat Sep 23, 2006 8:37 pm Post subject: Script: Get a list of all subfolders for use in other tasks |
|
|
User needs to get a list of subfolders with directory. Then for each subfolder , a directory loop task is run to get the first filename. Then a copy task is run to copy the first file to another folder.
Script is listed below. Change the source directory from "c:\\test" to your required directory. Test it and provide feedback. Some tweaking may be needed.
Last edited by melvin on Sat Sep 23, 2006 8:41 pm; edited 1 time in total |
|
Back to top |
|
 |
melvin Site Admin
Joined: 25 May 2006 Posts: 635 Location: Santa Barbara, california
|
Posted: Sat Sep 23, 2006 8:39 pm Post subject: |
|
|
import com.hitek.engine.mods.script.Script;
// define a vector (basically an array) to hold the list of subfolders
Vector folderList = new Vector();
// this function recursively gets the list of folders and adds them to the folderList vector
void listFolders(File root)
{
if (root != null && root.isDirectory())
{
final File[] contents = root.listFiles();
for (int k = 0; k < contents.length; k++)
{
if (contents[k].isDirectory())
{
folderList.add(contents[k]); //add folder to list
listFolders(contents[k]); //list directory again
}
}
}
}
//call the function to get the list in c:\test folder
//the listFolders(dir) call will fill the folderList vector with File objects corresponding to every subfolder
File dir = new File("c:\\test");
listFolders(dir);
// now for each folder, dynamically set the folderPath in the Directory Loop task and run the task
// lets assume your Directory Loop task title = dirLoop
// lets assume your Copy task title = copy
for (int i=0;i<folderList.size();i++)
{
String folderPath = folderList.get(i).getPath();
System.out.println("Folder = " + folderPath);
//now set the source folder in the dirLoop and copy tasks
//look at the task properties file in the Automize7\data\tasks folder using wordpad
//the parameter for the directory loop task source folder is Task.PARAMETERS1
Script.setPar("dirLoop", "Task.PARAMETERS1", folderPath);
//the parameter for the copy task source folder is also Task.PARAMETERS1
Script.setPar("copy", "Task.PARAMETERS1", folderPath);
// run the dirLoop task which in turn will call the copy task in the Task To Run field.
// exit code = 0 or -100 means successfull.
int exitCode = Script.run( "dirLoop" );
System.out.println("Exit code = " + Integer.toString(exitCode));
} |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|