Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


hblount
2014-05-19T13:04:08Z
Currently when running the File Copy task it is an all or nothing process. While you can add filters on date, filename, etc. you can't limit the number of files that are copied. For example if I have 1000+ files that meet the criteria for a copy I would like to only copy ten files, perform the next task to process these ten files and then loop and repeat.
Sponsor
Forum information
ErikC
2014-05-20T07:23:07Z
Hi hblount,

You can do this now. You have to make two jobs, one job will run the process (j1) and one job is handling the files (j2).

(j1) Run Process
(j1t1) Set Variable
(j1t2) .NET code Execute
(j1t3) Job/Task control
(j1t4) Calculate Variable
(j1t5) Set Variable

(j2) Process Files
(j2t1) Copy file

You have to have a int32 User Defined Variable. Call it LoopCounter.
In (j1t1) set this variable to 1.

Use this c# .NET code in (j1t2)
using System;
using System.IO;
using System.Text;

public class Test
{
 
 public static string GetFileSection(int counter, string path, string pattern)
 {
 	StringBuilder sb = new StringBuilder();
 	string[] files = Directory.GetFiles(path,pattern);
 	int MAX = 10;
 	for(int x = (counter-1)*MAX ; x<counter*MAX;x++)
 	{
 		try{sb.AppendLine(files❌);}
 		catch(Exception){}
 	} 	
 	return sb.ToString();
 }

}

For the counter you use {USERVAR(LoopCounter)}
Use the correct path and pattern to match your files.

(j1t3) Runs (j2)
(j1t4) This task adds one to the LoopCounter variable.
(j1t5) This task sets the LoopCounter to 0. You have to add a condition to this task. This condition checks if the output of the .NET task (j1t2) is empty. A match is Continue and no match has to be set to Next.

To complete (j1) there has to be a loop. The loop starts on (j1t2) and ends on (j1t5). The loop settings are: loop while {USERVAR(LoopCounter)} Not Equal to 0.

The next job (j2) is doing all your file handling. Could be more than one task if you want. But I did only the file copy task (j2t1). This task has a loop and uses the foreach setting. The input for the loop is the output of the .NET task (j1t2).



So j1 runs and will show all the files and j2 is handling the shown files.

Hope this helps you.

Regards,
Erik
Uses Visualcron since 2006.
Scroll to Top