# Renaming Directories after File Names

**URL:** https://resource.dopus.com/t/renaming-directories-after-file-names/33230
**Category:** Help & Support
**Tags:** rename
**Created:** [August 8, 2019, 7:20am UTC](https://resource.dopus.com/t/renaming-directories-after-file-names/33230 "2019-08-08T07:20:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![StuSmith](https://resource.dopus.com/user_avatar/resource.dopus.com/stusmith/32/33665_2.png) [@StuSmith](https://resource.dopus.com/u/StuSmith)
#### Post date: [August 8, 2019, 7:20am UTC](https://resource.dopus.com/t/renaming-directories-after-file-names/33230/1 "2019-08-08T07:20:29Z")

</div>

Hi Team,  
I have just moved my video collection onto a NAS and the Media Server I have installed on it has a prefered way of having the files named. All good and dandy. What I would like to do, is rename all the directories so they are identical to the largest file that is contained within each directory.  
I found an earlier post which contained -

Rename FROM {filepath|noterm|..} TO {file|noext}

which I placed in a button and works perfectly, trouble is, I have become tired of doing this after 60 directories. I have 1600 directories to go. Any help on being able to put this into a loop that goes through each directory and renames them is greatly appreciated.

Stu.

---

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [August 8, 2019, 9:40am UTC](https://resource.dopus.com/t/renaming-directories-after-file-names/33230/2 "2019-08-08T09:40:03Z")

</div>

Do you want to only rename selected directories (e.g. go to a certain folder, select-all, then click a button to rename those directories, but not directories _inside_ them)? Or do you want to rename directories recursively?

For each directory, do you want its name to be the same as the largest file _directly below_ the directory, or _anywhere below_ it, including sub-folders?

I'm assuming you want the extension taken off the end of the file (like in the example command), but if not let me know, or any other requirements.

---

<div class="post-metadata">

### Author: ![StuSmith](https://resource.dopus.com/user_avatar/resource.dopus.com/stusmith/32/33665_2.png) [@StuSmith](https://resource.dopus.com/u/StuSmith)
#### Post date: [August 8, 2019, 12:05pm UTC](https://resource.dopus.com/t/renaming-directories-after-file-names/33230/3 "2019-08-08T12:05:34Z")

</div>

Hi Leo,  
I was thinking somethin along the following lines:

Movies  
Good Movie 1080p DVD Subs  
Good Movie (1999).mp4  
Good Movie (1999) eng.srt  
Better Movie 720p noSubs {2010}  
Better Movie (2010).avi

Becomes

Movies  
Good Movie (1999)  
Good Movie (1999).mp4  
Good Movie (1999) eng.srt  
Better Movie (2010)  
Better Movie (2010).avi

A big Yes to both your queries. I would like to:  
1 - go to a certain folder, select-all, then click a button to rename those directories, but not directories _inside_ them  
2 - For each directory, I would like its name to be the same as the largest file _directly below_ the directory.

Thank you in advance,  
Stu.

---

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [August 9, 2019, 2:21pm UTC](https://resource.dopus.com/t/renaming-directories-after-file-names/33230/4 "2019-08-09T14:21:09Z")

</div>

Here's a rename preset which does that:

> [@Rename directory after largest child file](https://resource.dopus.com/t/rename-directory-after-largest-child-file/33244):
>
> This preset renames each selected folder to the same name as the largest file directly below it, with the file extension removed. Only files directly below each selected folder are considered. If you want the search to be recursive -- i.e. look for …

---

<div class="post-metadata">

### Author: ![StuSmith](https://resource.dopus.com/user_avatar/resource.dopus.com/stusmith/32/33665_2.png) [@StuSmith](https://resource.dopus.com/u/StuSmith)
#### Post date: [August 11, 2019, 1:06am UTC](https://resource.dopus.com/t/renaming-directories-after-file-names/33230/5 "2019-08-11T01:06:40Z")

</div>

Thank you very much Leo, that preset worked perfectly 😃
