Page 1 of 1

Building an archive structure by file names

Posted: Fri Jun 30, 2023 3:51 pm
by pfischer
Hello all,
I need some help with a switch task.

I want to archive PSD-files in a structure based on the file names.
The file name always consists of an 8-digit number.
I.e. from 00000001.psd to 99999999.psd

The archive folders should always contain a specified range of numbers.
E.G.:
00000001-00001999
00002000-00003999
00004000-00005999
Thus, a maximum of 2000 files per folder will be archived.

If now an image with the name "00012345.psd" exists, the archive folder should be called
be named 00012000-00013999.
So far I only manage to sort the files via endless manual filter specifications. Unfortunately, this is an extremely time-consuming and error-prone method.
Does anyone have an idea if this can be solved more elegantly with a little math and switch logic?

Thanks for your support.
Best regards,
Peter

Re: Building an archive structure by file names

Posted: Sun Jul 02, 2023 8:51 pm
by tdeschampsBluewest
Hi Peter,

Just put the following variables in a "Set hiearchy path" and here you are :

Code: Select all

[Job.NameProper:Search="^[0]+"][Switch.Calculation:Expression="round(([job.NameProper]/2000)-0.5)*2000"]-[Job.NameProper:Search="^[0]+"][Switch.Calculation:Expression="round(([job.NameProper]/2000)+0.5)*2000-1"]

Get the leading 0 :

Number of leading 0 is already contained in your jobName, just look for it with a regex :

Code: Select all

[Job.NameProper:Search="^[0]+"]
Calulate upper and lower value :

we need to "floor" or "ceil" the value divided by the range wanted then remultiply by itself
Exemple with lower limit

Code: Select all

floor(12345/2000)*2000
floor(6.1725)*2000
6*2000=12000
How to do it in with only "round" function :

Since we only have "round" function within switch, we need to force this behaviour by adding +0.5 and -0.5.
Lower :

Code: Select all

round(12345/2000 - 0.5)*2000
round(6.1725-0.5)*2000
round(5.1725)*2000
6*2000=12000
Upper :

Code: Select all

round(12345/2000)*2000
round(6.172560.5)*2000
round(6.6725)*2000
7*2000=14000
Switch version :

Code: Select all

[Switch.Calculation:Expression="round(([job.NameProper]/2000)-0.5)*2000"]
[Switch.Calculation:Expression="round(([job.NameProper]/2000)+0.5)*2000-1"]
Do not forget to remove 1 for the upper limit and here we go!

Re: Building an archive structure by file names

Posted: Wed Jul 05, 2023 10:40 am
by pfischer
Hi tdeschampsBluewest,

thank you for this clever solution and especially for the explanation!

Unfortunately, there is still an error (see screenshot).
Because of the better readability I used only the "start folders", i.e. the first part of your formula. So the folders should be as follows:
00000000
00002000
00004000
00006000
...

Strangely, for file names between 00000010 and 00000099 (6 leading zeros) or 00000100 and 00000999 (5 leading zeros) a separate folder with 6 or 7 zeros is created. Actually, these files should also be sorted into the folder with 8 zeros.
For files with 7 leading zeros (e.g. 00000001.psd) this also works correctly.

Do you have an explanation for this?

Thank you very much for your great and helpful support!

Kind regards,
Peter

Re: Building an archive structure by file names

Posted: Thu Jul 06, 2023 11:41 am
by tdeschampsBluewest
Hi,
Effectively, for file under the range index number of digits (4) and above 9, some problem can happen.

For example with 00000999 : the regex part will give 00000 the calculation part will give 0, and that's not the wanted number of digits.

Another solution, if you have the last version of switch + the new rename element version, is to use the "Add leading 0" action.

See example here