Rename files depending on how many files in folder

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

Rename files depending on how many files in folder

Postby mathewwhite » Wed Feb 17, 2021 4:37 pm

Hi there,

I hope someone may be able to help me?

I have many movie files in folders - some movies are a single file, some are split into 2 or more parts.

An example would be

FOLDER FILE NAME
Movie A Movie A
Movie B Movie B1 and Movie B2 (movie split in to 2 files)

I already know how to bulk rename all the movie files to match the folder names BUT, I want to add the text part1 and part2 to the split files and NOT the single files. I want the single files to remain just "Movie" name and only add Part1 and Part2 extentions on movies which have 2 or more parts.

An exmaple would be

FOLDER FILE NAME
Movie A Movie A
Movie B Movie B Part 1 and Movie B part 2

I hope this makes sense?

Thanking you in advance
Matt
mathewwhite
 
Posts: 4
Joined: Wed Feb 17, 2021 4:28 pm

Re: Rename files depending on how many files in folder

Postby Luuk » Wed Feb 17, 2021 9:40 pm

Greetings Matt. Im thinking the only way to conduct folders by "how many files" is with the javascript?
Im not understanding all of the \Folder\ and Filenames, but if this matches your NOW ===> NEW ...

\FolderA\FolderA.mp4 ===> \FolderA\FolderA.mp4 (Forbid rename because only one file)
\FolderB\FolderB1.mp4 ==> \FolderB\FolderB-part1.mp4
\FolderB\FolderB2.mp4 ==> \FolderB\FolderB-part2.mp4

Then maybe the RegEx(1) with "v2" can help with "Match" and "Replace" like...
(\d+)$/g
-part$1

The RegEx cannot test "how many files", but only is looking for names that end with a number!!
So then just inserting "-part" before the ending number, instead of testing "how many files".
Also maybe try something like !*part* *.mp* inside the Filters(12) Mask can help with previewing?
Luuk
 
Posts: 324
Joined: Fri Feb 21, 2020 10:58 pm

Re: Rename files depending on how many files in folder

Postby mathewwhite » Wed Feb 17, 2021 10:14 pm

Luuk

Thank you for taking the time to reply but, I am afraid to say, I dont understand!

Looks like I will have to make a start running through thousands of files and adjusting them all manually! :oops: :oops:

Thanks for the help
Matt
mathewwhite
 
Posts: 4
Joined: Wed Feb 17, 2021 4:28 pm

Re: Rename files depending on how many files in folder

Postby Luuk » Thu Feb 18, 2021 1:55 am

Sorry for the poor explanations. There is more ways, but also hard to explain, like another way can be first renaming the files like...

Name(2) is Remove
AppendFolderName(9) with Name=Prefix, Levels=1
Numbering(10) with Mode=Suffix, Start=1, Inc=1, Sep.=-part, and checkmark in "Folder"
Filters(12) with checkmarks only in "Files" and "Subfolder" and maybe *.mp4 in "Mask"

It conducts ALL the files to start like FolderName-part1.mp4, so then using a batch to fix the lonely files.
Like with the brc64 commandline, the batch to remove "-part1" from just the lonely files can be like..
Code: Select all
@echo off
cd /d "C:\YourMainFolder"
For /d /r %%a in (*) do @Dir /b /a-d "%%a" 2>nul |Find /c /v "" |Findstr "^1$" 1>nul && ^
"C:\YourPathTo\brc64.exe" /dir:"%%a" /regexp:"(.*)-part1$:\1" /execute
Pause
Luuk
 
Posts: 324
Joined: Fri Feb 21, 2020 10:58 pm

Re: Rename files depending on how many files in folder

Postby Luuk » Thu Feb 18, 2021 4:25 am

The first batch Im posted does not recurse all of the directories, so needing to add /recursive like this...

Code: Select all
@echo off
cd /d "C:\YourMainFolder"
For /d /r %%a in (*) do @Dir /b /a-d "%%a" 2>nul |Find /c /v "" |Findstr "^1$" 1>nul && ^
"C:\YourPathTo\brc64.exe" /recursive /dir:"%%a" /regexp:"(.*)-part1$:\1" /execute
Pause

Also if you like to experiment, you can remove /execute, so then clicking it gives preview instead of renaming.
Luuk
 
Posts: 324
Joined: Fri Feb 21, 2020 10:58 pm

Re: Rename files depending on how many files in folder

Postby mathewwhite » Thu Jul 22, 2021 3:55 pm

Luuk

Its been several months since your repsonse and I have only just seen it - sorry and thank you!

I have managed to get my files/folders all nicely in order and named, however, the last thing I am struggling with is removing the "part1" from movies that only have one part.

I notice that you have provided a script on how to tell BRU to go through and remove "part1" from any file where there isnt a part2. Sadly, I dont know where to begin with running this script and your help would be hugely appreciated.

thank you
M
mathewwhite
 
Posts: 4
Joined: Wed Feb 17, 2021 4:28 pm

Re: Rename files depending on how many files in folder

Postby therube » Thu Jul 22, 2021 4:16 pm

With Everything, you can easily find directories that contain "-part1" & not "-part2".

Code: Select all
child:<filename>   Search for folders that contain a child with a matching filename.

Code: Select all
child:-part1  !child:-part2

So that should point out all directories that you need to deal with.
(That assumes that each movie, multiple parts or not, would be in its own directory.)
therube
 
Posts: 1025
Joined: Mon Jan 18, 2016 6:23 pm

Re: Rename files depending on how many files in folder

Postby mathewwhite » Thu Jul 22, 2021 4:34 pm

Thanks Therube.

Each movie is in its own folder - about 50% are one single file, 45% two files and 5% three files.

I want single files just to be "moviename".
Double files as "Moviename part1" and "moviename part2"
Three files as "Moviename part1", "moviename part2" and "moviename part3"

With thousands of movies a manual deletion of "part1" from single movie files will take weeks!

with BRU i have managed to get them all named and ordered exactly as I want them - I just need to delete the "part1" from single files.

thanks
M
mathewwhite
 
Posts: 4
Joined: Wed Feb 17, 2021 4:28 pm

Re: Rename files depending on how many files in folder

Postby therube » Thu Jul 22, 2021 5:09 pm

Code: Select all
C:.
+---movie1
|       1.part1
|       
+---movie2
|       2.part1
|       2.part2
|       
\---movie3
        3.part1
        3.part2
        3.part3

Everything Search:
Code: Select all
C:\TMP\SEA\movies  child:part1 !child:part2

That search returns the directory name, movie1 (& not movie2 or movie3 - because they both have a "part2").

Drag the found directories into BRU.
You can set stuff like...

12:Filters, Mask: *part*
3:Replace, Replace: -part1, With:<nul>


(In the Everything search, my examples used "part" rather then "-part".
You'd want to change it to "-part".)


Take a couple directories, make copies of them, & play with the copies to see if it works as expected for you.
therube
 
Posts: 1025
Joined: Mon Jan 18, 2016 6:23 pm

Re: Rename files depending on how many files in folder

Postby Luuk » Thu Jul 22, 2021 7:11 pm

Its unfortunate, but I cant know which settings were used to conduct "nicely in order and named" ?
If using my 2nd-example, the names would look like... folder1-part1, folder2-part1, folder2-part2, etc ?
So then, they would need the 2nd-batch to recursively remove -part1 from all of the lonely files like folder1.

Im thinking maybe the easiest way is just like therube is now describing, if you dont want a batch for automation.
The batch depends on having the brc commandline version, and then it will conduct like the explanation.
But you would have to download if not having it already, and then modify these colored-parts...

@echo off
cd /d "C:\Path\To\YourMainFolder"
For /d /r %%a in (*) do @Dir /b /a-d "%%a" 2>nul |Find /c /v "" |Findstr "^1$" 1>nul && ^
"C:\Path\To\Your\brc64.exe" /recursive /dir:"%%a" /regexp:"(.*)-part1$:\1" /execute
Pause

Then you could put it in a file, name it with a .cmd or .bat extension, and then just click on it.
It conducts all folders beneath YourMainFolder, and only conducts lonely-files ending like... -part1.
If you remove /execute, it can present a "preview" for the renames, instead of renaming anything.

If not liking the batches, Im highly reccommend therube's method for dragging your files from the everything.exe window.
Then, bru only conducts the dragged files, just be careful not changing anything inside of Filters(12), or you have to drag them again.
Myself Im always preferring the batches, but also do understand that many users prefer having the gui control.
Luuk
 
Posts: 324
Joined: Fri Feb 21, 2020 10:58 pm


Return to BRU Support