hiteksoftware.com Forum Index hiteksoftware.com
User discussion forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Script: Get a list of all subfolders for use in other tasks

 
Post new topic   Reply to topic    hiteksoftware.com Forum Index -> Task Sequences, Chains and Scripts
View previous topic :: View next topic  
Author Message
melvin
Site Admin


Joined: 25 May 2006
Posts: 635
Location: Santa Barbara, california

PostPosted: Sat Sep 23, 2006 8:37 pm    Post subject: Script: Get a list of all subfolders for use in other tasks Reply with quote

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
View user's profile Send private message Send e-mail
melvin
Site Admin


Joined: 25 May 2006
Posts: 635
Location: Santa Barbara, california

PostPosted: Sat Sep 23, 2006 8:39 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    hiteksoftware.com Forum Index -> Task Sequences, Chains and Scripts All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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