Sign in

Batch Renaming Files Using Go

Have you ever wished that when you download pictures from your camera or phone to your computer that they are named in a more descriptive way instead of the generic numerical naming of 001.jpg, 002.jpg, etc? Well, now you can with my simple program written in Go. Please note you must have Go installed to use this program. This simple Go program can rename all files of virtually any file-type that you specified with the prefix that you provide it.

What is Go

Go is a programming language that was developed by Google. Go is quite fast and is great for manipulating folders and files on your computer.

Usage Example

Say you have a folder called “vacation_pics” and in it are images from your trip to Hawaii and they are all named in a generic numerical way. When you download those images to your computer they are named as DSC001.jpg, DSC002.jpg, DSC003.jpg. Using this simple program you can have those images be renamed toHawaii_1.jpg, Hawaii_2.jpg, Hawaii_3.jpg, by running just one execution instead of manually renaming them one by one.

This program uses flags to get user information to execute the code. Here’s all the flags available for this project.

To start, after you download the project from GitHub, drag your photo folder into the directory where you see the main.go file. After that, in your terminal navigate to directory where main.go lives and run:

$ go run main.go -filetype=.jpg -inputFolder=vacation_pics          -outputFolder=Vacation2021 -renameFileAs=Hawaii
Example on terminal, all go on one line

For this case the filetype that we want to change is .jpg, the inputFolder is called vacation_pics folder, and the outputFolder will be called as the Vacation2021 folder and we are renaming these files with the prefix of Hawaii.

After you run that command, your images should be renamed as as Hawaii_1.jpg, Hawaii_2.jpg, Hawaii_3.and stored in a folder called Vacation2021. You can change the output folder name by modifying the outputFolder flag, meaning give it another name besides Vacation2021. Similarly, you could change what you prefix the renamed files should take by changing the renameFileAs flag.


Above is an example to rename .jpg files but this program is able to batch rename files of virtually any file-type. This could be most useful when you scrape images or files online and they are named in a weird or generic way and you want to rename them to something that makes more sense to use later, like as training data for your machine learning model. But mainly the purpose of this program is to rename files into something that makes more sense to you to keep things more organized. Hope this program is useful, enjoy!

Building iOS and web apps