Create folder structure based on filenames

Questions and answers on how to get the most out of FFAStrans
Post Reply
ring4life70
Posts: 53
Joined: Thu Apr 15, 2021 6:22 am

Create folder structure based on filenames

Post by ring4life70 »

Hello all,
i need your help to define a final delivery process in my workflow, which creates a subfolder structure based on the naming convention of my source file.

Usually the naming convention of my file is:

TheEndgame_SE01_EP01.mxf

ie:

Tile_Season_episode_description

what I need, is to create a subfolder structure where i copy the file like the following:

Tile
Tile_Season
Tile_Season_episode
Tile_Season_episode_description
my file

just to better understand
Screenshot 2022-12-04 at 06.35.52.png
Screenshot 2022-12-04 at 06.35.52.png (116.06 KiB) Viewed 1234 times
i am trying using a populate metadata process before delivery process but i can not assign the correct parameters, can you please help me ?
thanks
emcodem
Posts: 1646
Joined: Wed Sep 19, 2018 8:11 am

Re: Create folder structure based on filenames

Post by emcodem »

Hey ring4life70, good to hear from you again!

No problem at all but the method that i use assumes that the characters _SExx and _EPxx do not occur in the %s_tile% part (xx means 2 numbers). If you fear it could happen that this could occur, let me know because we probably need another strategy.

Populate processor: (you have to "create" the corresponding user_variables that i use here on the left side:)

Code: Select all

%s_ep_description% = "1 HIGH RES"
%s_tile% = $regext("%s_original_name%","(.+?)_SE\d\d")
%s_tile_season% = $regext("%s_original_name%","(.+?)_EP\d\d")
%s_tile_season_episode%  = %s_original_name%
Note that the order of these instructsions does not play a role. $regext, explained:

() = use only the part inside the paranthesis. If we would not use (), e.g. we write the regex like ".+?_EP\d\d", the matched portion would include the _EP\d\d part.
.+? = this is my favourite regex, most of my regexes contain this. it means match everything up to or between. In our case as we start with .+?, it matches from "start" until what i worte after .+? (e.g. _EPxx)
_SE\d\d = match everything from start up to _SE followed by 2 numbers

Delivery processor:

Code: Select all

Folder = \\server\share\%s_tile%\%s_tile_season%\%s_tile_season_episode%\%s_ep_description%
Of course if you prefer you could just omit the variable definition for %s_ep_description% and instead write in the delivery processor like this:

Code: Select all

Folder = \\server\share\%s_tile%\%s_tile_season%\%s_tile_season_episode%\1 HIGH RES


On a sidenote, you store the title 3 times in the folder structure and 1 time in the filename, is that really neccessary? Wouldn't a folder structure like "Title\SE01\EP01" do the job?
emcodem, wrapping since 2009 you got the rhyme?
ring4life70
Posts: 53
Joined: Thu Apr 15, 2021 6:22 am

Re: Create folder structure based on filenames

Post by ring4life70 »

Hi emcodem,
thanks for your time, the populate node works as desired, thanks again, however I have another issue, when I go to extract multiple audio CH from a file I have to move all the extracted tracks to the same folder as you can see in the screenshot below:
Screenshot 2022-12-04 at 21.46.16.png
Screenshot 2022-12-04 at 21.46.16.png (163.4 KiB) Viewed 1195 times
as you can see for the audio file we are using the same naming convention with the addition of the description of the CH Audio.
for all the audio files the naming convention is:

TheEndgame_SE01_EP_01_CH01.wav

Thanks
ring4life70
Posts: 53
Joined: Thu Apr 15, 2021 6:22 am

Re: Create folder structure based on filenames

Post by ring4life70 »

solved :D
i changed the variable, %s_tile_season_episode%

from:

%s_tile_season_episode% = %s_original_name%

to:

%s_tile_season_episode% = $regext("%s_original_name%","(.+?)_CH\d\d")

and used the following formula in the delivery node:

D:\LOCAL STORAGE\%s_title%\%s_title_season%\%s_title_season_episode%\AUDIO

concerning the possibility that the characters _SExx and _EPxx also appear in the %s_tile%, yes it could be possible, do we have a plan B ?

And again, is not really neccessary that we store the title 3 times in the folder structure, yes a structure like "Title\SE01\EP01" could be fine.
emcodem
Posts: 1646
Joined: Wed Sep 19, 2018 8:11 am

Re: Create folder structure based on filenames

Post by emcodem »

ring4life70 wrote: Mon Dec 05, 2022 7:10 am solved :D
...
Well done, looks like you have no problem understanding the regexes that i used 8-)
ring4life70 wrote: Mon Dec 05, 2022 7:10 am And again, is not really neccessary that we store the title 3 times in the folder structure, yes a structure like "Title\SE01\EP01" could be fine.
concerning the possibility that the characters _SExx and _EPxx also appear in the %s_tile%, yes it could be possible, do we have a plan B ?
Sure we can be a little more strict with the regex matching in order to avoid matching _EPxx within the title, we just need to further define our regex.
Why don't we use the same regex for all the parts and just move around the parantheses:

Code: Select all

$regext("%s_original_name%","(.+?)_SE\d\d_EP\d\d$")
This matches the "tile" part and it says that _SE\d\d_EP\d\d must be at the end (the dollar sign does this magic).

Now to get the SE part, we just move the ():

Code: Select all

$regext("%s_original_name%",".+?_(SE\d\d)_EP\d\d$")
You get the idea?

Of course, if there is an error in the naming, the regex will return empty "" string. If it is a human that is responsible for the correct naming of the input file, you better to an explicit check for this, e.g. after the populate processor, insert a conditional that throws an error in case...

Also and alternatively, to give you a little bit more to chew on, we could potentially check if each single part is empty and if that is the case, assign it a default value. In a populate processor, in an additional line after all the regex magic, insert a line like that:

Left side: %s_tile%,
Right side:

Code: Select all

"%s_tile%" = "" ? "coolDefaultValue" : "%s_tile%"
This technique is called ternary operator, could also be called IF THEN ELSE. Just look for the definition of ternary in the internet, it should be simple to understand ;-)
emcodem, wrapping since 2009 you got the rhyme?
ring4life70
Posts: 53
Joined: Thu Apr 15, 2021 6:22 am

Re: Create folder structure based on filenames

Post by ring4life70 »

Hi emcodem,

thank you very much for your solutions, I'll do some testing, and in case I come back with other questions.

thanks again
Post Reply