Renaming folder name same as one of the file inside.

Bulk Rename Utility How-To's

Renaming folder name same as one of the file inside.

Postby Zekrye » Thu Aug 11, 2022 7:20 pm

Hello, I hope this has not been answered yet because I cant find the one that really fit to my problem.

I have lots of jumbled folder name but the file inside at least have .txt and that txt is important. so is it possible to make the parent folder name same as the .txt file?

I.E. /jumbledmess1337/correctname.txt to /correctname/correctname.txt

Cheers.
Zekrye
 
Posts: 2
Joined: Thu Aug 11, 2022 7:15 pm

Re: Renaming folder name same as one of the file inside.

Postby Luuk » Thu Aug 11, 2022 9:50 pm

When the bru is renaming any file/folder, it will never look at another file/folder.
If its me, I would probably just write a script to look inside the folders, before renaming them.
Luuk
 
Posts: 689
Joined: Fri Feb 21, 2020 10:58 pm

Rename folder to its only settled filename.txt

Postby Luuk » Fri Aug 12, 2022 1:32 am

This command to look inside of all sub-folders, and find any folders with having only one .txt-file inside...
For /f "delims=" %A IN ('dir/b/s/ad^|Sort/r') DO @Dir/b "%A\*.txt" 2>nul|Find /c /v ""|Findstr "^1$" 1>nul && For /f "delims=" %B IN ('dir/b "%A\*.txt"') DO @echo "%A" ----- "%~nB"

It does present a 'preview' to the screen like.... "C:\Path\To\Your\Folder-Name" ----- "New-Folder-Name" (from .txt-file)
If satisfied with "New-Folder-Names"?, first remove ----- and then change @echo ===> @ren to conduct the folder renames.
Extra spaces around ----- wont matter because Im always using extra anyways, and it begins renaming at the deepest folders first.

Must remember there is no way to "undo", unless saving the output from the first command!!
Luuk
 
Posts: 689
Joined: Fri Feb 21, 2020 10:58 pm

Re: Renaming folder name same as one of the file inside.

Postby Zekrye » Mon Aug 15, 2022 4:23 am

Thank you for the solution, I dont think Im that savvy with scripting but i'll try and see if it work.
Zekrye
 
Posts: 2
Joined: Thu Aug 11, 2022 7:15 pm

Rename folder to its only settled filename.txt

Postby Luuk » Mon Aug 15, 2022 6:42 am

If not familiar with the command-line, first just type a command like... cd /d "C:\Path\To\Your\Main-Folder"
Then just type cd again, to verify that you are at the correct Main-Folder.

Then, to paste the long command after copying it... Right-click the top-left icon, then Edit, then Paste.
It does find all sub-folders with only one .txt-file (there can be other file-types, but only one .txt-file).
Then it just presents them to the screen like.... "C:\Path\To\FolderNowName" ----- "FolderNewName".

If the list is very long, and you like to make a preview-file, or just save a copy of the original names...
Just add > "C:\Users\YourUserName\Desktop\My-folder-preview.txt" to the very end of the command.
Then just make sure the preview-file is settled at your desktop, before conducting the renames.

If ready to edit the command for renaming, remember it only conducts folder-names with exactly 1 .txt-file inside.
Any folders with no .txt-files or with 2-or-more .txt-files, will not be shown in the preview, and will not be renamed.
Luuk
 
Posts: 689
Joined: Fri Feb 21, 2020 10:58 pm


Return to How-To