cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member
Member

Wait for 3 files with same name but different prefixes at different times of the day

Jump to solution

Good Morning. I have a customer who needs a flow as follows: The FreeFCORE flow must wait for up to 03 files that will arrive in the hotfolder at different times of the day with the following BOL, CTE and NFE prefixes and which must contain the same order number, the file name should follow the following pattern:
PREFIX THAT INDICATES THE TYPE OF THE DOCUMENT: 3 characters (BOL, CTE or NFE)
UNDERSCORE (UNDERLINE) = _
ORDER NUMBER CONTAINING NINE NUMBERS
UNDERSCORE (UNDERLINE) = _ or .PDF (TO INDICATE THE TYPE OF THE PDF FILE) or FINAL.PDF TO INDICATE THAT IT IS THE LAST FILE TO BE RECEIVED AND THAT THE JOB MUST BE SUBMITTED TO PRINTING

FreeFlow Core must join the files of the same order number and release the file immediately for printing when it receives the file with _FINAL.PDF extension. For example, if FreeFlow Core received a file called CTE_109051169.pdf you must wait until it receives a file called NFE_109051169_FINAL.pdf or BOL_109051169_FINAL.pdf.

Below are 3 examples of expected file name combinations (there may be any combinations, the important thing is that the work should be joined and released as soon as you receive the file with _FINAL extension):

BOL_109051169_FINAL.pdf
CTE_109051169.pdf
NFE_109051169.pdf

CTE_109051168_FINAL.pdf
BOL_109051168.pdf

BOL_109051167_FINAL

I thank you for your support.

Élvio

Tags (2)
0 Kudos
5 Replies
Highlighted
FreeFlow Production Workflow Moderator
FreeFlow Production Workflow Moderator

Re: Wait for 3 files with same name but different prefixes at different times of the day

Jump to solution

FFCore does not have an "open" job state where documents can be submitted at different times and be in the same job group. Also, the different documents composing a single print submission must be members of the same job group. One can designate in MAX submissions that documents are part of the same job group using the Group Key and Order ID.

In other words if you had script that:

  1. collected the documents with the same order number until the "FINAL" document appeared
  2. formed a csv file which contained information on the documents with a common Group Key number
  3. loaded the documents on Core in the same location as designated by the csv file
  4. drop the csv file in the hotfolder containing the desired WF

You could achieve your goal. Unfortunately it is complicated and FFCore is not a big help in reducing the complexity.

Highlighted
FreeFlow Production Workflow Moderator
FreeFlow Production Workflow Moderator

Re: Wait for 3 files with same name but different prefixes at different times of the day

Jump to solution

You could try something like this:

$in = "C:\test\in\"
$out = "C:\test\out\"
$ffc_hf = "C:\test\hf\"
$filter = "*.pdf"
$fsw = New-Object IO.FileSystemWatcher $in, $filter -Property @{IncludeSubdirectories = $false}
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier Created -Action {
$files = Get-ChildItem -Path $in -Recurse -File
$regex = '(\d+)'
foreach ($file in $files)
{
$ordernumber = ($file.Name -split $regex)[1]
$path = Test-Path "C:\test\out\$ordernumber.txt" -PathType Leaf
if (-not $path) {
Set-Content -Path "C:\test\out\$ordernumber.txt" -value "C:\test\out\$file;$ordernumber;1"
} else {
Add-Content -Path "C:\test\out\$ordernumber.txt" -value "C:\test\out\$file;$ordernumber;1"
}
Get-ChildItem -Path $in -Recurse -File | Move-Item -Destination $out
if ($file -like '*FINAL*') { Copy-Item -Path "C:\test\out\$ordernumber.txt" -Destination $ffc_hf}
}
}

Here is the idea:

A watched folder $in for pdf files is created. When a pdf arrives in the $in folder, a textfile for a specific order number is created (Set-Content) in the out folder if it is the first pdf with a specific order number. The text file will contain a link to the pdf, the order number and an id=1 (that could be used as GroupKey). If not (i.e. if a pdf file with a specific order number has already arrived) then a new line will be added (Add-Content) to the existing text file. The pdf files are then moved to the folder $out and if the pdf arriving contains "FINAL" then the textfile will be copied to the folder $ffc_hf. You would here need to change the $ffc_hf path to your FFCore hotfolder.

The result for your example copied to $ffc_hf would using your example would be three text files named by order number:

109051167.txt will contain:
C:\test\out\BOL_109051167_FINAL.pdf;109051167;1

109051168.txt will contain:
C:\test\out\BOL_109051168.pdf;109051168;1
C:\test\out\CTE_109051168_FINAL.pdf;109051168;1

109051169.txt will contain:
C:\test\out\CTE_109051169.pdf;109051169;1
C:\test\out\NFE_109051169.pdf;109051169;1
C:\test\out\BOL_109051169_FINAL.pdf;109051169;1

You then need to map the fields for the text files in the MAX Setup on the hotfolder in FFCore:

A=File name
B=OrderID
C=GroupKey

To run the attached script you can right click it and select Run with PowerShell, but the folder $in will only be watched as long as PowerShell stays open. To make the script run in the background you can for instance use Windows Task Scheduler and create a new basic task and in Actions select Start a program:

Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

For Arguments use something like:
NoExit -WindowStyle Hidden -noprofile -executionpolicy bypass -file C:\scripts\watchfolder_wait_create_max.ps1

Highlighted
Member
Member

Re: Wait for 3 files with same name but different prefixes at different times of the day

Jump to solution

Hi Stefan! Thank you so much for sharing your knowledge! I will test this solution next week. Best regards!!!

0 Kudos
Highlighted
FreeFlow Production Workflow Moderator
FreeFlow Production Workflow Moderator

Re: Wait for 3 files with same name but different prefixes at different times of the day

Jump to solution

Hi Elvio,

Noticed a typo. The Arguments I use in the Windows Task Scheduler for running the script are:

-NoExit -WindowStyle Hidden -noprofile -executionpolicy bypass -file C:\scripts\watchfolder_wait_create_max.ps1

With a minus character (-) before NoExit.

Stefan

Highlighted
Member
Member

Re: Wait for 3 files with same name but different prefixes at different times of the day

Jump to solution
Thanks again Stefan!
0 Kudos