22 Votes

Rename File to its Folder Name

Tutorial by Stefan Trost | Last update on 17.02.2018 | Created on 23.04.2016

Recently, someone asked me whether it is possible to use the FileRenamer for renaming a file in a way that the folder name of the file becomes part of the filename. At this time, it was not possible. However, in between, I have developed such a function and in this tutorial, I would like to show how to use it.

The program File Renamer can be downloaded for free on this page (for Windows, Mac OS X and Linux) and for renaming we are using placeholders in all example which are explained here in detail but also in the following.

In each case, first, we have to add the files we would like to rename to the application, for example with dragging the files onto the program. You can adjust the desired changes on the right of the program, you can see a preview directly in the file list and with clicking the button "Apply Changes", you can rename all files in the list.

Folder Name should be attached to File Name

In our first example, we would like to supplement our origin filename with the name of the first direct folder with adding the name of the folder to the beginning of the file name. That is for example:

BEFORE:  C:\Holiday\Trip to Norway\Image 1.jpg
AFTER:   C:\Holiday\Trip to Norway\Trip to Norway Image 1.jpg

For this, we are using the function "Mask" that you can find in the right column under "Changes" > "Name". As mask, we are using "%folder-1% %name%" with which we are directly getting what we want.

The placeholder %folder-1% is standing for the first folder below the file ("Trip to Norway" in this case) and the placeholder %name% will be replaced with the old name of the file ("Image 1" here). Additionally, we are writing a space between the placeholders to ensure that the characters will not be written directly after each other.

File Name should contain multiple Folder Names

Beyond referring to the direct folders as we have done in the first example, it is also possible to reference deeper folders and to mix multiple folders in one mask. The placeholder %folder-1% always stands for the direct folder, the placeholder %folder-2% for the folder name one level deeper and so on. Here is an example:

BEFORE:  C:\Documents\Work\2016\Ready\01\Invoice.pdf
AFTER:   C:\Dokuments\Work\2016\Ready\01\Work Invoice 012345.pdf 

In this example, accordingly, %folder-1% is standing for the folder "01", %folder-2% is standing for the folder "Ready", %folder-3% is standing for the folder "2016", %folder-4% is standing for the folder "Work" and %folder-5% is standing for the folder "Documents". We want to rename the file to "Work Invoice 012345.pdf". For that, we are using the mask "%folder-4% %name% %folder-1%-%folder-3%". As you can see, we can arbitrarily order the placeholders, we can omit for benevolence and we can mix them up with other characters.

Count Folders from below or above

With the previously discussed placeholders %folder-1%, %folder-2%, %folder-3% and so on, we have counted the folder in the path from above, that means from the file (% folder-1% is the folder directly below the file).

If we use positive numbers instead of the negative numbers -1, -2, and -3, using the wildcards %folder1%, % folder2%, %folder3%, and so on, we can also count from below. %folder1% is the first folder in the path, %folder2% is the second folder in the path, and so on.

Delete, Insert or Replace Folder Name

The placeholders standing for the folder names can also be used in the functions "Search and Replace", "Insert" and "Delete Text". So, you are able to replace parts of the old filename with folder names, you can insert the name of the folder at an arbitrary position within the file name or you can selectively delete the folder names from file names.


About the Author

AvatarYou can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile


Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.