Big Problem for me - fix 1st letter of folders

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

Big Problem for me - fix 1st letter of folders

Postby wakrajci » Mon Jun 30, 2025 5:59 pm

Forgetting the power of BRU, I hastily deleted the 1st letter of folders in a very large array. I did not discover it for a few days later.Thankfully the files in the folder have the same name. The folder contains about 4000 folders with files in them. I have been working on this problem for a while, and I can't seem to get it right. I want to copy the 1st letter of the file in each folder and add it to the beginning of the folders name:
Example: ape Fear (1991) --- Cape Fear (1991).mkv --- Cape Fear (1991).
A File in that folder

Please help!!
wakrajci
 
Posts: 3
Joined: Mon Jun 30, 2025 5:35 pm

Re: Big Problem for me

Postby Admin » Tue Jul 01, 2025 3:48 am

You can fix the folder names by using Bulk Rename Utility's JavaScript renaming feature to copy the first letter of a file inside each folder and prepend it to the folder name. Here's a step-by-step approach:

1. Open Bulk Rename Utility and navigate to the parent folder containing the 4000 folders.

2. Make sure you have the option to include folders in the file list (Filters (12) ? check "Folders").

3. Select all the folders you want to fix.

4. Go to the Special (14) section and enable "Javascript Renaming."

5. Enter a JavaScript script like the following (adjust as needed):

Code: Select all
```javascript
// Only process folders
if (object("isdir")) {
    // Get list of files inside this folder
    var files = listFilesInFolder("*.*", false, false);
    if (files.length > 0) {
        // Get the first file's name (without extension)
        var firstFileName = removeExt(files[0]);
        if (firstFileName.length > 0) {
            // Get the first letter of the first file's name
            var firstLetter = firstFileName.charAt(0);
            // Prepend this letter to the folder name
            newName = firstLetter + origName;
        } else {
            newName = origName; // no change if no file name
        }
    } else {
        newName = origName; // no change if no files
    }
} else {
    newName = origName; // no change for files
}
```

6. Preview the changes to ensure the folder names will be corrected as expected.

7. If satisfied, click Rename to apply the changes.

This script works by checking each folder, listing the files inside it, taking the first letter of the first file's name, and adding that letter to the start of the folder name.

Make sure to back up your data before running batch renames. Also, test on a small subset first to confirm it works as you want.
Admin
Site Admin
 
Posts: 2944
Joined: Tue Mar 08, 2005 8:39 pm

Re: Big Problem for me - fix 1st letter of folders

Postby wakrajci » Tue Jul 01, 2025 3:51 pm

Hi Admin,
I'm new to Javascript so please bear with me:
- On Filter (12), should I have Folders and files, or just folders included?
- On the Javascript you sent me should I copy and paste '''javascript with the rest of the script?

Thanks for the help!
wakrajci
 
Posts: 3
Joined: Mon Jun 30, 2025 5:35 pm

Re: Big Problem for me - fix 1st letter of folders

Postby wakrajci » Tue Jul 01, 2025 7:30 pm

Hi again Admin,
You’re amazing! I have been trying to get this done for weeks without JavaScript and you did it in minutes. WOW! I was so impressed I went ahead and got a Home License. It looks like I need to learn JavaScript. What JavaScript version should I start with?
I played with your script for a while, and I got it to work by eliminating the first and last ‘’’ lines. I forgot to mention that I corrected a few 100 folder names to its file names manually. So, when I ran the script it gave me a lot of double first characters.
Is there something I can add to this script to check if the name has already been corrected and if so, skipped to the rest of the JavaScript?
Thank You!
wakrajci
 
Posts: 3
Joined: Mon Jun 30, 2025 5:35 pm


Return to BRU Support


cron