An example of using the Progress object

Hello everyone!

Can anybody give an example of the using the Progress object? I can't understand how to manage it. How to use the increment by files and by bytes?

What are you aiming to use it for? Things like progress-by-bytes are only used in quite rare cases with scripts, where the script itself is probably processing data byte by byte.

If you can tell us more about what you're doing, we can make an example that's tailored to that (or tell you that the progress object won't work for what you want, if that's the case :slight_smile:).

M'kay. Suppose there is the following code snippet:

		var Files = new Enumerator(clickData.func.sourcetab.selected_files);
		Files.moveFirst();

		while (!Files.atEnd())
		{
			
			Hashes = DOpus.FSUtil().Hash(Files.item(), "md5,sha");
			
			Txt += Files.item().name + "\n\n" + 
				"  [md5]\t" + Hashes(0).toUpperCase() + "\n" +
				"  [sha]\t" + Hashes(1).toUpperCase() + "\n\n\n";

			Files.moveNext();
		}

I need the progress bar was filling after processing each file. Or after processing each byte in the file (this is preferable, but impossible apparently). What Progress object methods should perform and in what sequence?

[code]@script JScript

function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection

  var fsu = DOpus.FSUtil;

  var Files = clickData.func.sourcetab.selected_files;

  var Progress = clickData.func.command.progress;
  Progress.pause = true; // Allow pause button.
  Progress.abort = true; // Allow abort button.
  Progress.Init(clickData.func.sourcetab, "My Progress");
  Progress.AddFiles(Files.count);
  Progress.Show();

  var Txt = "";

  var Files = new Enumerator(Files);

  while (!Files.atEnd())
  {
        var abortState = Progress.GetAbortState();
        if (abortState == "a")
              break; // Aborted.
        if (abortState == "p")
        {
              DOpus.Delay(500);
              continue; // Paused; restart the loop to see if we are still paused.
        }

        Progress.SetName(Files.item().name);
        // DOpus.Delay(500); // Can be useful if testing with small files.
  
        var Hashes = fsu.Hash(Files.item(), "md5,sha");
     
        Txt += Files.item().name + "\n\n" + 
              "  [md5]\t" + Hashes(0).toUpperCase() + "\n" +
              "  [sha]\t" + Hashes(1).toUpperCase() + "\n\n\n";

        Files.moveNext();
        Progress.StepFiles(1);
  }

}[/code]

Thank you. It is quite confusing. A similar example would be worth to add to the guide.