script get oldest file from directory

Post Reply
borisCM
Member
Posts: 37
Joined: Mon May 06, 2019 12:23 pm
Location: Netherlands

script get oldest file from directory

Post by borisCM »

Hi,

i'm new to this forum. been using switch for quit some time. but i ran into an issue that i can't fix (i'm not realy an expierenced scripter).

Our screening software can't handle the speed of our renderes, therefor the plate order gets mixed up.
so i need a flow which creates a time gab between two files, so the software has more time to proces the files.
i started with the space jobs option of the 'hold job' , but as it turns out that doesn't ensure first in first out, so the plates got even more mixed.
I had an explanation of the switch helpdesk why not, but no out of the box solution for how to fix it.

i was thinking of a script that would look into a folder and get the oldest file and inject that one.
does someone have that already written? it whould help me a lot.


Thanks
Boris
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: script get oldest file from directory

Post by cstevens »

I normally do an entryList on a Dir object for something like this:

Code: Select all

function timerFired( s : Switch )
{
	var inFolder = new Dir("C:/Shared");
	var fileList = inFolder.entryList("*.pdf", Dir.Files, Dir.Time|Dir.Reversed);
	s.log(1, "Oldest file in folder is: " + fileList[0]);
	var job = s.createNewJob();
	//job.sendToSingle(inFolder.path + "/" + fileList[0] );
}	
This code would find a list of all the .pdf files in the "C:/Shared" directory, sort them by reversed time (oldest to newest), then put the oldest file name in the log and optionally send it to the outgoing connector of the script. If you want all files change the filter to "*.*" or whatever file type you are looking for.

The whole entryList filtering / sorting method is kind of complex, but very handy. You can read more about it here:

https://www.enfocus.com/manuals/Develop ... lass.html
borisCM
Member
Posts: 37
Joined: Mon May 06, 2019 12:23 pm
Location: Netherlands

Re: script get oldest file from directory

Post by borisCM »

Hi Cstevens
Thanks for the info!!
Post Reply