Image
LOADING
Innovative IT Solutions for Businesses of All Sizes

ARTICLE

Image
February 26 2023

Efficient File Management: How to Rename Multiple Files at Once with an Excel/Spreadsheet Script in…

Image
Ahsan Firdaus
Go To Original Article

Efficient File Management: How to Rename Multiple Files at Once with an Excel/Spreadsheet Script in Mac/Linux Based

Photo by Rubaitul Azad on Unsplash

Intro

If you’ve ever found yourself with dozens or even hundreds of files that need to be renamed, doing it manually can be a time-consuming and tedious process. However, with a simple script created using Microsoft Excel or Google Spreadsheet, you can quickly and easily rename multiple files at once. This process involves creating a script in Excel that generates a series of commands to rename each file based on your desired naming convention. In this article, i will guide you through the steps to create this script and show you how to use it to rename multiple files in just a few clicks. Whether you’re organizing a collection of photos, renaming documents for a project, or simply cleaning up your computer, this technique can save you a significant amount of time and effort. So let’s dive in and learn how to automate the file renaming process with an Excel script!

Pre Requisite’s

  1. Mac OS, Linux Based OS (maybe you can use Linux Windows bash, im not tryin yet) → i will create for Windows native version, so stay tune 🤩
  2. Microsoft Excel or Google Spreadsheet
  3. Terminal

Step by step

Get all filenames

  1. Open the terminal on your computer
  2. Navigate to the directory you want to list the files in using the “cd” command. For example, if you want to list the files in a directory named “Documents” on your desktop, you would type cd ~/Desktop/Documents
  3. Once you are in the directory, type ls -1 and press Enter.
  4. The terminal will then display a list of all the file names vertically in the directory
  5. Copy list, block all list file and press Command + C
Terminal Command

Listing names in Excel

  • Open Microsoft Excel/Google Spreadsheet, create new Sheet
  • Create new columns: original_name, rename_file, script
  • Paste lists in original_name column, press Command + V
  • Create a list to be renamed in rename_file column
Read too: Perform Print Merge on Figma with Composer Plugin

Base Script For Rename

Renaming a file in the Mac terminal is a straightforward process. To do so, you will use the “mv” command, which stands for “move”. First, open the terminal on your Mac and navigate to the directory where the file is located using the “cd” command. Alternatively, you can use the full path of the file if you know it. Once you are in the directory, type mv oldfilename newfilename and press Enter, replacing “oldfilename” with the current name of the file and “newfilename” with the new name you want to give it. For example, if you want to rename a file named “file1” to “newfile”, you would type mv file1 newfile. Press Enter to execute the command. The file will now be renamed with the new name you specified.

Combine the mv command in Excel

  • Use CONCATENATE formula to combine command
  • Type =CONCATENATE("mv ";"""";A2;"""";" ";"""";B2;".pdf";"""") in formula bar and press Enter
  • Drag to duplicate

Make .sh file and do Some Magic 🪄

To create a .sh file, also known as a shell script, follow these steps:

  • Open a text editor such as Notepad, VS Code, or TextEdit. I am using VS Code to do this.
  • Copy all from srcipt column and paste
  • Save the file with a .sh extension in where you put rename file directory. For example, you could name the file “run.sh”.
  • Set the file’s permissions to allow it to be executed. To do this, open the terminal and navigate to the directory where the file is located. Type the following command : chmod +x run.sh
  • To run the script, type ./run.sh in terminal, this will execute the commands
  • And you can see the files is automated rename !

Conclusion

In conclusion, using an Excel or Spreadsheet script to rename multiple files at once is a simple and efficient way to manage your files. By creating a script that generates a series of commands to rename each file based on your desired naming convention, you can save a significant amount of time and effort when organizing your files. Whether you’re renaming photos, documents, or any other type of file, this technique can streamline your file management process and improve your productivity. With the steps outlined in this article, you can easily create your own Excel script and automate the file renaming process.