How to move files into subfolders based on file names

Bulk Rename Utility How-To's

How to move files into subfolders based on file names

Postby mayawilliams » Sun Nov 14, 2021 6:42 pm

Hi everyone,

I would like to move files into their own subfolders based on their filenames.

So I currently have one folder which contains for example:

blue-2021-11-14-0001
blue-2021-11-14-0002
blue-2021-11-14-0003
blue-2021-11-14-0004
red-2021-11-14-0001
red-2021-11-14-0002
red-2021-11-14-0003
red-2021-11-14-0004
yellow-2021-11-14-0001
yellow-2021-11-14-0002
yellow-2021-11-14-0003
yellow-2021-11-14-0004

Now I want to move each file that STARTS with "blue" into a subfolder named "blue", each file that STARTS with "red" into a subfolder named "red" and so on.

Please let me know if this is possible and what I will have to do to accomplish this.

Thank you????
mayawilliams
 
Posts: 4
Joined: Sun Nov 14, 2021 6:33 pm

Re: Move files into subfolders based on filenames

Postby Luuk » Sun Nov 14, 2021 8:47 pm

Would first need to see the now-names ====> new-names, so this answer is just guessing about '-' after the colors?
First to put a checkmark inside the menu "Renaming Options, Advanced Options, Allow Using \ in Renaming Criteria"
Then inside of RegEx(1), can use a "Match" and "Replace" like...

^(blue|red|yellow)-(.+)
\1\\2
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to move files into subfolders based on file names

Postby mayawilliams » Mon Nov 15, 2021 12:20 am

Hi,

Thank you for the quick reply.

Unfortunately, I don't think this solves my problem quite yet, because in my case I don't have only blue, red and yellow as file names, I have literally thousands of different file names with an extension like this "-2021-11-14-0001" which is basically the date the file was created + number.

What I'm looking for is a way to make BRU realize that the last 16 characters (date + number) should be ignored and then group all files with the same name (excluding last 16 characters) and then move them into their own folder. The folder's name should be the name of the files without the last 16 characters of course.

Sorry this is a bit complicated but I would really appreciate your help.
mayawilliams
 
Posts: 4
Joined: Sun Nov 14, 2021 6:33 pm

Re: How to move files into subfolders based on file names

Postby Luuk » Mon Nov 15, 2021 4:33 am

Would probably need some different now-names ====> new-names, so this still guessing...
1) All files are named like... SomePrefix-yyyy-mm-dd-FourNumbers?
2) SomePrefix is not always one word, so not always a color?
3) All folders should be the whole prefix before -yyyy-mm-dd-FourNumbers?
4) ALL files should have this prefix removed?

So if all four is correct, then inside of RegEx(1), can use a "Match" and "Replace" like...
^(.+)-((19|20)\d\d-[01]\d-[0123]\d-\d{4})$
\1\\2

So then renaming like...
a s d-1921-11-14-0001.txt ===> a s d\1921-11-14-0001.txt
blue-2021-11-14-0001.txt ====> blue\2021-11-14-0001.txt
blue-2021-21-14-0001.txt ====> (not renamed, bad mm)

If not wanting to remove the prefix from filenames, edit the "Replace" to \1\\1-\2
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to move files into subfolders based on file names

Postby mayawilliams » Mon Nov 15, 2021 11:15 pm

Hi Luuk,

You are understanding my question quite well, but you will have to explain to me in just a bit more detail, because I'm still not understanding 100% haha.

the first 3 is correct, the 4th one is not, because I want to keep the filenames exactly the same.

I just want to move all files into their own subfolder based on their prefix. So I'm basically looking for a way to tell BRU "ignore the last 16 characters and group all files with the same name (without last 16 characters) into their own subfolder."

If you could maybe type out the exact "Replace and Match" that I'll have to use for this, it will be much appreciated.

Also, I was wondering if BRU has a wild card character?

Thank you again
mayawilliams
 
Posts: 4
Joined: Sun Nov 14, 2021 6:33 pm

Re: Move files into folders based on names

Postby Luuk » Tue Nov 16, 2021 1:15 am

To keep all of the filename characters, can either use the edited "Replace" that was at the very bottom.
Or just change both of the "Match" and "Replace" to something like...
^((.+)-(19|20)\d\d-[01]\d-[0123]\d-\d{4})$
\2\\1

The RegEx(1) can use wildcards like...
. ======= Any character
\d ====== Any digit
[a-e] === Either a, b, c, d, or e
[1-4] === Either 1, 2, 3, or 4
[123] === Either 1, 2, or 3

Can also add quantifiers to say how many like...
\d+ ======== 1-or-more digits
\d{4} ======= 4 digits
\d{4,} ====== 4-or-more digits
[012]{2,7} == 2-thru-7 digits
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: Move files into folders based on names

Postby Luuk » Tue Nov 16, 2021 1:20 am

The last example of ....
[012]{2,7} == 2-thru-7 digits, butt all digits should be 0, 1, or 2.
So this could match any numbers looking like... "00", "01111", "0120122".
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to move files into subfolders based on file names

Postby mayawilliams » Tue Nov 16, 2021 8:12 pm

Okay so I found a replace+match that works pretty well:

Match : (\D+)(.*)
Replace: \1\\1\2

That did exactly what I wanted, except it didn't keep the folder names 100% because it kept everything except for the numbers (some filenames had numbers before the last 16 digits) and also it added the "-" into the folder name...

If you can maybe tell me how I can keep the full folder name and remove the "-" I will be really thankful

Thank you
mayawilliams
 
Posts: 4
Joined: Sun Nov 14, 2021 6:33 pm

Re: Move files into subfolders based on filenames

Postby Luuk » Wed Nov 17, 2021 3:20 am

^(.+)-((19|20)\d\d-[01]\d-[0123]\d-\d{4})$
\1\\2
Renames like...
11 s d-1921-11-14-0001.txt ===> 11 s d\1921-11-14-0001.txt
yellow-2021-11-14-0001.txt ===> yellow\2021-11-14-0001.txt

Or just edit the replace like \1\\1-\2 to get...
11 s d-1921-11-14-0001.txt ===> 11 s d\11 s d-1921-11-14-0001.txt
yellow-2021-11-14-0001.txt ===> yellow\yellow-2021-11-14-0001.txt

=================================================================
This some other "Match" and "Replace" to conduct similiar...
^((.+)-(19|20)\d\d-[01]\d-[0123]\d-\d{4})$
\2\\1

^((.+)-\d{4}-\d\d-\d\d-\d{4})$
\2\\1

^(.+)-(\d{4}-\d\d-\d\d-\d{4})$
\1\\1-\2

=================================================================
The (\D+)(.*) could move, and also rename any file, unless the filename does only have digits.
The (\D+) removes leading digits, and only stops matching at the end, or right before the next digit, so like...
11 s d-1921-11-14-0001.txt ====> s d-\ s d-1921-11-14-0001.txt
red-2021-11-14-0001.txt ======> red-\red-2021-11-14-0001.txt
abcd.txt ====================> abcd\abcd.txt
12abcd.txt ==================> abcd\abcd.txt

You can improve (\D+)(.*) by putting a - inbetween the groups, and then using \1\\1-\2 for the replace.
But this does still not grant matching any digits, that might be needed for some foldernames.
So its best using (.+) at the beginning, when knowing they end like -(\d{4}-\d\d-\d\d-\d{4})$
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm


Return to How-To