Append File name to folder?

A swapping-ground for Regular Expression syntax

Append File name to folder?

Postby Xandur » Thu Dec 13, 2007 2:31 pm

Hello!

First, outstanding app! BRU has allowed me to organize and rename my music collection in a fraction of the time it would have otherwise. For a guy who's has mild OCD (my wifes diagnosis lol), being able to capitalize each word in a songs title has given me many nights of peaceful sleep. :)

Anyway,

I'm trying to rename folders with the title of an .avi file within that folder. I have 100's of .avi movies. I'd like each one to be placed into a folder named the same name as the movie. I see the "append folder name" option in BRU, but not an "append file name" option. is there a way to do this?

example:

NewFolder/Honeymoon.avi -> Honeymoon/Honeymoon.avi


Thanks
Xandur
 
Posts: 3
Joined: Mon Jan 22, 2007 8:30 pm

Postby Admin » Thu Dec 13, 2007 6:22 pm

Hi,

Welcome to the OCD club :D :D :D

Unfortunately no, BRU doesn't have this capability. However, if you can generate a list of folder names and file names you can probably manipulate them a little bit in Notepad or Excel, and then use the Rename Pairs facility.


Jim
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Append File name to folder?

Postby Xandur » Sun Dec 16, 2007 5:42 pm

Great idea; that should work perfectly. Thanks!
Xandur
 
Posts: 3
Joined: Mon Jan 22, 2007 8:30 pm

Re: Append File name to folder?

Postby GMA » Wed Dec 19, 2007 6:57 am

Hi, Xandur:
I believe the following is the fastest way to achieve what you're looking for without having to install any extra software.
Sorry if this post gets long, but I'll try to be as thorough as possible so anyone with the same needs as Xandur but maybe less computer knowledge will be able to follow the steps.

For this example, lets say you have a folder in your C: drive named "Movies", inside of which there are four folders (could be 50, 300, it doesn't matter), each one containing only a movie file. That is:

C:\Movies\New Folder\Honeymoon.avi
C:\Movies\New Folder 2\The Godfather.avi
C:\Movies\Other folder name\Star Wars 2.avi
C:\Movies\Any folder name\Taxi Driver.avi


The following five steps will explaing how to rename those folders using the name of the file they contain. It's quite simple and you'll have it done in less than 5 minutes, even if there are hundreds of folders to be processed.

-----------------------------------------------------------------------------------------------------------------------------------

1. Open the comand line by going to Start > Run and typing cmd. Now, type the following (remember I used "C:\Movies" for this example; change that to the corresponding directory in your hard drive):

dir C:\Movies /b /s > C:\FileList.txt

Press Enter. That will generate a text file in C: named "FileList", with exactly this content:

C:\Movies\New Folder
C:\Movies\New Folder 2
C:\Movies\Other folder name
C:\Movies\Any folder name
C:\Movies\New Folder\Honeymoon.avi
C:\Movies\New Folder 2\The Godfather.avi
C:\Movies\Other folder name\Star Wars 2.avi
C:\Movies\Any folder name\Taxi Driver.avi


2. Open this file with Notepad (this is not the text editor of my choice, but I will use it for this example because obviously everyone using Windows has it), and remove the first four lines (they are four in this example). As you can see, those lines are only folder names; we just need the lines with "folder + file" names.

3. Now, open the Replace function in Notepad (Edit > Replace). In the Find what field, type C:\Movies\ and leave the Replace with field empty. Press Replace all and you should have this:

New Folder\Honeymoon.avi
New Folder 2\The Godfather.avi
Other folder name\Star Wars 2.avi
Any folder name\Taxi Driver.avi


4. Open Replace once more. In Find what type \ and in Replace with type | (note that this is a vertical bar, AKA "pipe" or "Sheffer stroke", not a lowercase "L" nor an upercase "i"). Press Replace all and the final result wil be:

New Folder|Honeymoon.avi
New Folder 2|The Godfather.avi
Other folder name|Star Wars 2.avi
Any folder name|Taxi Driver.avi


5. Save the changes and close Notepad. Open Bulk Rename and go to "C:\Movies". Now go to File > Import Rename-Pairs and open "FileList.txt". Go to Actions > Select all (or press CTRL+A) and see how the folders will be renamed according to the contents of "FileList.txt". The only thing left to do is to set the Remove > Last n function in BRU to 4 (that way you avoid giving an extension to the folder). If everything looks correct, you can now press Rename and you're done.

-----------------------------------------------------------------------------------------------------------------------------------

I hope this was (or will be) of any help.
Cheers,

Gabriel
Mar del Plata, Argentina

PS: Can I join the club? But only if the number of current members is not a round number. I don't wanna make a mess...
GMA
 
Posts: 91
Joined: Sun Dec 02, 2007 1:30 pm
Location: Argentina

Re: Append File name to folder?

Postby KHL » Wed Dec 19, 2007 6:21 pm

Hi Gabriel,

perfect description! As even I have understood the procedure, I guess nobody will answer anymore...

By the way, what does the OCD club mean? I'm very sure I'm a member already but would like to know what's my handicap, lol.

Karl
KHL
 
Posts: 128
Joined: Wed Mar 09, 2005 8:59 pm
Location: Germany

Re: Append File name to folder?

Postby Admin » Wed Dec 19, 2007 8:22 pm

Obsessive Compulsive Disorder. Those of us who won't let a problem beat us, no matter what :-)



Jim
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Append File name to folder?

Postby LouieChuckyMerry » Mon Dec 02, 2013 3:34 am

First, thanks to GMA for a very useful tutorial :D . Second, in case someone else finds it helpful, this method also works for a directory with single (or multiple) subfolder(s). Simply follow GMA's kind guide, but when you get to 2. delete all entries without a file extension (as only the file names are needed for the renaming of their respective containing folders) and when you get to 3. use Find what and Replace with as many times as necessary to winnow the "FileList" to the necessary level of "OriginalFolderName | FileNameToBeUsedForRenamingOriginalFolderName.ext" (that is, you need to Replace with an empty field all of the preceeding subfolder levels until the strings are only two levels long, the original folder and its original file). Then continue with the rest of the steps, noting that in 5. instead of selecting all you'll only want to select the last level of subfolders for renaming (that is, only select the folders containing the files used for renaming).
LouieChuckyMerry
 
Posts: 4
Joined: Mon May 10, 2010 10:26 am


Return to Regular Expressions