Rename folder by file's first word?

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Rename folder by file's first word?

Postby someoneabc » Wed Nov 30, 2011 8:05 pm

Hello everyone,

My problem is somewhat weird but I think there has got to be a way around it.
Suppose I have the following files:

Tokyo - Madrid.doc
Tokyo - New York.doc
London Tokyo New York.doc
2011 London New York.doc
2011 - Anonymous.doc

I would like to create new folders named by the first word of the file only. And then move these files into them. So in this case I will only have 3 folders for the 5 files:

Tokyo> Tokyo - Madrid.doc
Tokyo> Tokyo - New York.doc
London> London Tokyo New York.doc
2011> 2011 London New York.doc
2011> 2011 - Anonymous.doc


I have thousands of these files and I would really appreciate if someone showed me if this can be done in BRU. I googled it and my problem seems unique.

Thanks..
someoneabc
 
Posts: 7
Joined: Sun Apr 29, 2007 3:22 pm

Re: Rename folder by file's first word?

Postby bitmonger » Thu Dec 08, 2011 9:32 am

Bulk Rename is always my goto program for renaming.
However, in this case I don't think it is designed to create directories from parts of the name.
Rather than leave you without a solution I would respectfully suggest another free renaming program called PFrank.
found at:
http://www3.telus.net/pfrank/

It allows a special (?B) extension to the regex which does exactly what you want - (it allows a forward slash to be used in the replace to indicate creation of a subdirectory)

Use (?B)^([^ ]+)(.+) as your search pattern
and \1/\1\2 in your replace pattern

Let's use Tokyo - Madrid.doc as an example

^([^ ]+) captures everything up to the first space into \1 i.e. Tokyo
the (.+) captures the rest of the filename into \2 i.e. - Madrid.doc

The forward slash tells the program you want to use whatever is before it as a new subdirectory, with what follows as the filename within that subdirectory.

so the replace \1/\1\2 would translate to Tokyo\Tokyo - Madrid.doc

Worked fine on my machine.

HTH,
Bit
bitmonger
 
Posts: 50
Joined: Sat Sep 22, 2007 5:05 am

Re: Rename folder by file's first word?

Postby r0tt3nnn » Tue May 28, 2024 11:56 pm

13 years late to the party, but wanted to add my $0.02 - not sure if BRU has added features, or maybe they were there all along, but I just found a way to use BRU to create a new folder for each file and move it into that folder. Here are the steps for doing that with these example file names:

Movie Name1 (2019)#Details Details.mkv
Movie Name2 (2020)#Details Details.mkv
Movie Name3 (2024)#Details Details.mkv

Step 0: Navigate to the folder where your files are, and select all the ones that apply
Step 1: Go to the Renaming Options Menu -> Advanced Options sub-menu -> Click 'Allow using \ in Renaming Criteria for creation of New Folders'
Step 2: In the RegEx section, put a check in the `v2' box (below the fields), for the Match field put something like this... (.*)# ...bit of explanation - the brackets mean 'capture group", and the # is the delineating character that tells the capture group where to stop, but could be any pattern (in my case, the files are all movies, so I want the name and year at the filename's beginning to be used for the folder name, but not the rest of the filename that follows that pattern), and in the Replace field, put... $1\\$1 ...yes, double slash! (not sure why that's needed, took trial and error to figure it out, and that's the only way I could get the $1 variable to work twice.)
Step 3: Hit the big Rename button, and it'll ask you for permission to create all the folders, and then it'll create the necessary folder and move the file there, looking like this:

Movie Name1 (2019)\Movie Name1 (2019)#Details Details.mkv
Movie Name2 (2020)\Movie Name2 (2020)#Details Details.mkv
Movie Name3 (2024)\Movie Name3 (2024)#Details Details.mkv

Hope that helps!
r0tt3nnn
 
Posts: 2
Joined: Tue Apr 12, 2022 8:55 pm


Return to BRU Support