OL Learn

Copy PDFs to 1 Folder and Mix all when copy end

Hello, I’ve tried the following but it doesn’t work.
I have a recording folder, in which PDFs come manually by copying, from these individual PDFs it should make 1 PDF at the end, but only if no new PDF comes into the folder.
The problem is due to the copying of 100 PDFs and a time setting for the pickup of 1min, which causes when I copy and it is just before the minute that the files are not all in the folder.
How can the control of the PDF only be picked up if no new file has been received for 10-20 seconds?
I thought about a trigger file, but if it ends up in the folder beforehand and the PDFs are not all in the folder, the same thing happens.
Thanks

Dear Marko,

First of all, welcome to the OL Learn forum!

When you manually paste PDF files into a specific folder, and you’re free to use for example a text file as trigger file, you can set up a Workflow process like the following:

  1. Folder Capture
    • Folder list: C:\in
    • Masks: *.txt
  2. Branch
    1. Folder Capture
      • Folder list: C:\in\pdf
      • Masks: *.pdf
    2. Execute the required plug-ins to merge the PDF input files…
  3. Delete

Where you trigger the Workflow process by dropping for example a text file in the folder of the first Folder Capture Workflow plug-in after you’ve pasted all the required PDF files in the correct input folder.

Many Thanks.
Then I would have to copy the txt manually. Thats not good.
It would be nicest if he can monitor a folder and if no new file is received for 20 seconds, he merges the existing files.
Everything has to be in 1 PDF for the workflow.
Concatenating more than 300 files is extremely time consuming.

Are there any other possibilities that the individual PDFs are not mixed immediately if one is in the folder but only later?
But it also runs automatically?
A folder recording “C: \ in” that has a counter for the receipt of the PDF and moves the files somewhere else “C: \ mix” and the action mixing only begins when he has the number he counted in “C: \ in”?

Here’s a relatively simple way to do this. Well… simple if you like scripting… :slight_smile:

Create a process that uses a Folder Listing Input task. Specify the appropriate folder and set the file mask to *.pdf. Using a Folder Listing task ensures that the process only runs if there are PDF files in the monitored folder. You can set that process’ Polling Interval to something like 5 seconds.

Then, immediately after the input task, add a Script condition task (just drag and drop a Run Script task and select Insert as Condition from the popup menu), with the following code:

var WAIT_TIME = 30000

var holdingFile = Watch.ExpandString("xmlget('/files[1]/folder[1]',Value,KeepCase,Trim)")+"holding.txt";
var fileCount = Watch.ExpandString("xmlget('/files[1]/@count',Value,KeepCase,NoTrim)")*1;
Watch.Log(holdingFile,2);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var holding;
result = false;

var diffCount=0;
if(fso.fileExists(holdingFile)){
  holding = fso.OpenTextFile(holdingFile,1);
  var lastRun = JSON.parse( holding.ReadAll());
  holding.Close();

  var lastDate = lastRun.date;
  var lastCount = lastRun.count;
  var timeDiff = Date.now()-lastDate;
  diffCount = fileCount-lastCount;
  Watch.log("Time since last run : "+timeDiff,2);
  result = ((timeDiff)>WAIT_TIME) && (!diffCount);
  if(diffCount) {
    Watch.Log("Found "+diffCount+" new file(s)",2);
    writeFile(fileCount);
  } else if(result) {
    fso.DeleteFile(holdingFile);
  }
} else {
  writeFile(fileCount);
}
Script.ReturnValue = result;

function writeFile(fCount){
  Watch.Log("Creating/Resetting Holding file",2);
  holding = fso.CreateTextFile(holdingFile);
  holding.write( JSON.stringify( {date:Date.now(), count: fCount*1} ));
  holding.Close();
}

You should adjust the first line of the script to specify the number of milliseconds after which the merging occurs. The default value in the script is 30 seconds.

The script reads the number of files from the Folder Listing task and stores it, along with a time stamp, as a JSON object in a file named Holding.txt. The next time the process runs, the script checks if the Holding.txt file exists and if it does, it loads it and compares the number of files stored in there with the current number of files in the folder. Three things can happen:

  • Same number of files and more than 30 seconds have elapsed: the script deletes the Holding.txt file and returns true. It’s in the True branch of the condition that you can use the PDF Merge task to merge all the PDFs in the folder.
  • Number of files has changed: the script recreates a new Holding.txt file with a new time stamp and the new file count, and then returns false.
  • Same number of files and 30 seconds have not yet elapsed: the script does nothing and returns false.

Attached is the sample Workflow config Delayed Process.OL-workflow (19.2 KB) I used to test the process. You may have to tweak things here and there but overall it should let you do what you wanted to achieve.

cool thanks, but the script become a error.
16:41:02.870 [0001] input folder : C:\PlanetPress Connect\Workflow_Designer Datei\Workflow Arbeitsordner\Tagespost - Verarbeitungsordner\Prima PDF Sammeln
16:41:02.871 [0001] parsed input folder : C:\PlanetPress Connect\Workflow_Designer Datei\Workflow Arbeitsordner\Tagespost - Verarbeitungsordner\Prima PDF Sammeln
16:41:02.871 [0001] mask : *.pdf
16:41:02.871 [0001] parsed mask : *.pdf
16:41:02.881 [0001] Plugin Ordnerliste completed successfully - 16:41:02 (elapsed time: 00:00:00.011)
16:41:02.882 [0002] Run embedded script…
16:41:02.882 [0002] W3602 : Error 0 on line 3, column 104: Kompilierungsfehler in Microsoft VBScript: Anweisungsende erwartet
16:41:02.882 [0002] W3603 : Error running script.
16:41:02.882 [0002] Skript ausführen: W1603 : Plugin failed - 16:41:02 (elapsed time: 00:00:00.001)
16:41:02.882 [0002] Error raised, considering it as false
16:41:02.882 [0002] Plugin Skript ausführen completed successfully - 16:41:02 (elapsed time: 00:00:00.001)
16:41:02.882 [0005] Deleting file : job010A0OEX5N9FE623343025B.dat, size: 1604 bytes
16:41:02.882 [0005] Plugin Löschen completed successfully - 16:41:02 (elapsed time: 00:00:00.000)
Prima PDF Sammeln Test (thread id: 6588) complete - 16:41:02 (elapsed time: 00:00:00.013)

Is there a solution for this?

I tested it here again, and I even created the same folder structure you have (C:\PlanetPress Connect\Workflow_Designer Datei\Workflow Arbeitsordner\Tagespost - Verarbeitungsordner\Prima PDF Sammeln\) and it works fine.

Did you change anything in the script? Could you post a sample XML file from the Folder Listing task?

Hello, it works. The Problem was the Emulation in this process. i must set the Debugger to XML and then it works. big thanks, it works very fine but the script is not so easy :slight_smile: