Create new "grouping" folder and move X folders into it?

Bulk Rename Utility How-To's

Create new "grouping" folder and move X folders into it?

Postby Graavarg » Thu May 26, 2022 12:19 pm

Hi,
Been scanning the forum for some hours and have found some "almost fitting" answers, and been trying for a few days to get it to work, but even with the manual + a regex manual and some earlier experience of using regex (and lot of experience using BRU, one of the very best tools on the entire internet) I just can't seem to get this to work, so I am asking for help.

I have +200000 folders with standardized names in this format: "nnnnnnn (XXXXXX) - zzzzzzz", where:

- "nnnnn" is a string of different length, including spaces, numbers and some special but filename-compatible characters (mostly characters like "ü", "ä", "ö" etc.). There can be any number of folders sharing the same "nnnnnn" (usually between 1-50, not that it matters).

- "(XXXXXX)" is a numeric code with zero-padding enclosed in a space + parenthesis => always in the form of " (" + 6 digits + ") ".

- "zzzzzzz" is a character jumble = any number of filename-compatible characters including space, but always at least 1 character in length, and always with the "- "-prefix (or " - " if you like).

- The "(XXXXXX) - zzzzzz"-combination is unique for every "nnnnnn", but only as a combination (the same "(XXXXXX)" and "- zzzzzz" can occur, but any combination of the two is unique).

All these folders reside in one single "megasuperfolder" (if anyone is interested these are automatically collected and stored movement-triggered wildlife surveillance video snippets on a NAS, just don't ask me why this has been done this way or I might reconsider jumping out the window...).

What I would like to do is go through the entire megafolder and CREATE new folders named "nnnnnn" (for every unique nnnnnn, which IRL is the name of the location of the wildlife cam) and then MOVE all folders and their content that are sharing that same "nnnnnn" INTO the newly created (grouping) folder AND RENAME them in the process by removing the "nnnnnn" (and the following single space) from the moved folders.

Just to be über-clear...
I want to go from a (shit-)load of folders (all containing multiple files) that are named:

qazxswedc dd ttt (123456) - fhh abbetcx/any number of files
qazxswedc dd ttt (444111) - kdjflk ll kkk/any number of files
dhh kkds jjjd (985566) - jhhfdjk i8/any number of files
dhh kkds jjjd (772511) - fhfhfh ggg/any number of files
dhh kkds jjjd (985566) - hatt ttt ttt/any number of files

to a hierarchical 2-tiered folder structure sorted at the upper folder level on the "nnnnnn"-part, with the lower folder level keeping the truncated version "(XXXXXX) - zzzzzz" of the original folder and with all the files being moved with/staying in the new subfolders:

qazxswedc/(123456) - fhh abbetcx/the same any number of files
qazxswedc/(444111) - kdjflk ll kkk/the same any number of files

dhh kkds jjjd/(985566) - jhhfdjk i8/the same any number of files
dhh kkds jjjd/(772511) - fhfhfh ggg/the same any number of files
dhh kkds jjjd/(985566) - hatt ttt ttt/the same any number of files

I know this is doable, but I &%¤#& can't get it to work.

/Mike
Graavarg
 
Posts: 2
Joined: Thu May 26, 2022 11:34 am

Re: Create new "grouping" folder and move X folders into it?

Postby Luuk » Thu May 26, 2022 4:23 pm

Im probably not to answer for many very hours yet, but there is some different ways to conduct a move like this description.
With the paid version, javascript can conduct this in just 1-rename, but otherwise its taking 2-renames to conduct the same.
But first must describe why "dd ttt" should be deleted? Should all words after the 1st-word inside 'nnnnn' be at least 4-chars long?
Luuk
 
Posts: 689
Joined: Fri Feb 21, 2020 10:58 pm

Re: Create new "grouping" folder and move X folders into it?

Postby Graavarg » Thu May 26, 2022 5:00 pm

I couldn't let it be (of course), and I just got it to work. Of sorts, since from a regex viewpoint it is quite "unelegant". On the other hand it highlights how bloody elegant BRU is :).

My whole process got "tilted" due to me not selecting the "v2"-box in the RegEx-compartment, and then desperately creating more and more complex regex-code (that didn't work, of course). In the end it was too simple (after dotting the "v2-box)": I just used "\s\(" to replace the "space"+"("-string with a backslash ("\" in the Replace field), which handled creating the correct new top-tier directory and the shortened second tier sub-directories perfectly.

I "lost" my 1st parenthesis in the replace (ending up with "XXXXXX)" instead of "(XXXXXX)", but that was easily added back as a second process.

I'm sure there is a more elegant one-step solution out there, but the main thing was finding something that worked. Sorry if I inconvenienced someone by asking for help, but I was pretty desperate this morning... :D
Graavarg
 
Posts: 2
Joined: Thu May 26, 2022 11:34 am


Return to How-To