Wait until job folder is empty flow

Post Reply
netaware
Newbie
Posts: 16
Joined: Tue Jul 30, 2024 7:11 pm

Wait until job folder is empty flow

Post by netaware »

Hello,
I want to send an email out whenever a job folder is empty.

Trying to achieve a flow to delete old working files.

What i am trying to achieve delete files in a folder, at a certain time, once that is completed, ie job folder is empty, send an email stating the folder is now empty.

I do not know how to make Switch wait until job folder is empty.

Any ideas?
User avatar
magnussandstrom
Advanced member
Posts: 510
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Wait until job folder is empty flow

Post by magnussandstrom »

This was a tricky one :D

My idea for "send an email when the folder is empty":

1. FireStarter to repeat a dummy job (You can adjust how often you like to check the folder)
2. Inject Wildcard (Look for any file *.* in your folder. If found > discard and recycle dummy job, if not found > send mail)

Unfortunatly with this solution you will get an email everytime the dummy job is triggered until there are files in the folder again. But maybe someone else have a good solution for that.

is_folder_empty.png
is_folder_empty.png (134.07 KiB) Viewed 51165 times
Last edited by magnussandstrom on Thu Apr 03, 2025 9:44 pm, edited 6 times in total.
User avatar
magnussandstrom
Advanced member
Posts: 510
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Wait until job folder is empty flow

Post by magnussandstrom »

..and to delete files in the specified folder, you have a couple of options:

Use File Pool Cleanup from the Folder Apps bundle.

Alternatively, you can schedule the Inject Job app to insert a dummy job at a specific time (using the output connection), and then use the Inject Wildcard app to delete the files.
RunDontStop
Member
Posts: 67
Joined: Mon Apr 05, 2021 8:03 pm

Re: Wait until job folder is empty flow

Post by RunDontStop »

I made a flow that may be what you need.

First, a hot folder and you can input any file you like (just one file) once the flow is finished and ready.

Then Scan Hierarchy. You use this app to scan the folder in question. Your target folder is the Hierarchy top folder. Set to scan for file, all subfolder search levels. The name is variable * wildcard. Name should match the filter. This means any file found returns a match.

For Private Data Key, ScanForEmpty. You can name the dataset something similar but you don't really need it.

You can let the outgoing connection be both success out and warning out.

After the Scan For Hierarchy connection you have one folder, and then from that you need to branch off to 2 different folders. For one connection: [Switch.Calculation:Expression=[ScanForEmpty.itemsFound"]" is equal to 0. The other connection, all other jobs (make certain to set this, don't leave it on All Jobs).

For the all other jobs connection: let the file continue to a Hold Job (delay of 1 hour, or whatever you need). After that the file empties into the original hot folder. So it goes through the whole process every hour. Keep in mind: better to have this end element as a second folder in the canvas, even though it points to the same starting hot folder location. This way the job can start over each time properly.

For the other connection, where it found zero items. Add a connected folder after that. Then this will branch off to two things. First, Mail send. Then it also empties into what will be a second hot folder, in the same flow (after a hold of 1 hour or so).

This second sub-flow is very much like the first. It scans the same target folder using Scan Hierarchy and does it every hour. Build this sub flow to look the same as the first. The only difference is: when it finds zero, it just repeats this second sub-flow, emptying into the second hot folder each time. If it finds more than zero, it reroutes and empties into the first hot folder of the flow, to restart that process. Just remember, make the end points as separate elements in the flow from the starting hot folders (even though they are the same folder in Finder or Explorer).

This flow should send out one email when your target folder has zero files. If at any point it goes above zero files, and then drops back to zero again, you will get another email. The only hang up is: if your target folder has a bunch of empty folders in it, you would get the email then. I am not sure if you would have that situation. I tested with an invisible file in my target folder and scan Hierarchy overlooked it (I hope you have the same result, invisible files can be common in Mac and Windows). I have attached a screen shot of example flow.
Scan For Zero.png
Scan For Zero.png (54.49 KiB) Viewed 50991 times
netaware
Newbie
Posts: 16
Joined: Tue Jul 30, 2024 7:11 pm

Re: Wait until job folder is empty flow

Post by netaware »

Wow! thanks for the advice! it looks harder to do then i realized.

i am going to try these and see how they work.

Thank you again :)
User avatar
JimmyHartington
Advanced member
Posts: 453
Joined: Tue Mar 22, 2011 7:38 am

Re: Wait until job folder is empty flow

Post by JimmyHartington »

I have made a script element which can monitor a folder at a defined interval.
For my use case it outputs a text-file and a privadata key with the number of files in the defined folder. No output if zero files.
But it should be trivial to modify to do the reverse.
Will try to make it for you next week.
User avatar
JimmyHartington
Advanced member
Posts: 453
Joined: Tue Mar 22, 2011 7:38 am

Re: Wait until job folder is empty flow

Post by JimmyHartington »

Here is my script element.
https://d.pr/f/VVXg0d

It uses the Time Fired function of a script. So you define at which interval it needs to check your choosen directory.
The output is a text-file with Private Metadata named what you define. And it contains the number of files in the directory.
Just route the one with 0 to send the e-mail.

Image
netaware
Newbie
Posts: 16
Joined: Tue Jul 30, 2024 7:11 pm

Re: Wait until job folder is empty flow

Post by netaware »

Sorry it took me so long to get back to you on this.

This is what I was looking for! But I could ask for one more thing?

Could I get filenames and dates in the log file?

My reason is that my flow sometimes creates problem jobs, not frequently, which I have send me an email. However, when a new user, which I am not aware of, sometimes sends files that are not allowed, causing many errors. So when there are many problem jobs, I dont want 100 emails, just one telling me that and gives me file names.

I would attempt to edit your script, however I am not a great coder and really don't know node.js.

Please feel free to tell me to go jump, if its a lot of work LOL

I hope to hear from you soon and thank you :)
User avatar
JimmyHartington
Advanced member
Posts: 453
Joined: Tue Mar 22, 2011 7:38 am

Re: Wait until job folder is empty flow

Post by JimmyHartington »

I am actually in the process of getting an app into the Enfocus App store based on this script.
V1 will set a JSON dataset on the job with this info.

Code: Select all

{
  "directory": "/Users/jh/TEST Number of items",
  "fileCount": 9,
  "fileTypes": { "pdf": 9 },
  "items": [
    { "name": "Sample file 1.pdf", "type": "pdf" },
    { "name": "Sample file 2.pdf", "type": "pdf" },
    { "name": "Sample file 3.pdf", "type": "pdf" },
    { "name": "Sample file 4.pdf", "type": "pdf" },
    { "name": "Sample file 5.pdf", "type": "pdf" },
    { "name": "Sample file 6.pdf", "type": "pdf" },
    { "name": "Sample file 7.pdf", "type": "pdf" },
    { "name": "Sample file 8.pdf", "type": "pdf" },
    { "name": "Sample file 9.pdf", "type": "pdf" }
  ],
  "timestamp": "2025-04-24T17:58:24.035Z"
}
But I have already other plans for v1.1.
Is it the date of the file you need. I think I would then look into adding both creation date and modification date.

Right now I have this extra info in v1.1 per file in the dataset.

Code: Select all

    {
      "name": "Sample file 1.pdf",
      "path": "/Users/jh/Temporary/Test/Sample file 1.pdf",
      "type": "pdf",
      "size": 1131294,
      "sizeHuman": "1.08 MB"
    }
Here I could add the 2 dates.
User avatar
JimmyHartington
Advanced member
Posts: 453
Joined: Tue Mar 22, 2011 7:38 am

Re: Wait until job folder is empty flow

Post by JimmyHartington »

V1.1 will now report this info about a file.

Code: Select all

    {
      "name": "Sample-file 1.pdf",
      "nameProper": "Sample-file 1.pdf",
      "path": "/Users/jh/Temporary/Test/Sample-file 1.pdf",
      "type": "pdf",
      "sizes": {
        "sizeInBytes": 1088894,
        "sizeInKilobytes": 1063.37,
        "sizeInMegabytes": 1.04,
        "sizeInGigabytes": 0,
        "sizeInTerabytes": 0,
        "sizeHuman": "1.04 MB"
      },
      "createdDate": "2024-10-30T11:19:37",
      "modifiedDate": "2025-05-08T08:39:27",
      "timeZoneName": "Europe/Copenhagen"
    }
netaware
Newbie
Posts: 16
Joined: Tue Jul 30, 2024 7:11 pm

Re: Wait until job folder is empty flow

Post by netaware »

Wow! looks great. Thanks for trying this out!

Let me know when it is complete and/or available in the appstore.
User avatar
magnussandstrom
Advanced member
Posts: 510
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Wait until job folder is empty flow

Post by magnussandstrom »

Nice work, Jimmy! This really makes me want to start building apps too, I just got the scripting license. :D
User avatar
JimmyHartington
Advanced member
Posts: 453
Joined: Tue Mar 22, 2011 7:38 am

Re: Wait until job folder is empty flow

Post by JimmyHartington »

netaware wrote: Thu May 08, 2025 2:44 pm Wow! looks great. Thanks for trying this out!

Let me know when it is complete and/or available in the appstore.
Version 1 of the app is now live in the app store.

https://www0.enfocus.com/en/appstore/pr ... -directory
User avatar
JimmyHartington
Advanced member
Posts: 453
Joined: Tue Mar 22, 2011 7:38 am

Re: Wait until job folder is empty flow

Post by JimmyHartington »

And now version 1.1 has been send to approval at Enfocus.
If approved it will include the file names, created and modified dates and file sizes in the JSON data set.
User avatar
JimmyHartington
Advanced member
Posts: 453
Joined: Tue Mar 22, 2011 7:38 am

Re: Wait until job folder is empty flow

Post by JimmyHartington »

Version 1.1 is out now.
It is possible to scan sub-directories.
File sizes, created and modified dates are added to the JSON.
Post Reply