This Go project provides a command-line tool named renamer 🚀 for renaming multiple files within a specified directory by adding either a prefix or a suffix to their existing names. 📝
- Bulk Renaming: 💨 Efficiently renames a large number of files.
- Prefix Addition: ➕ Adds a specified prefix to the beginning of filenames.
- Suffix Addition: ➡️ Adds a specified suffix to the end of filenames, correctly handling file extensions. 🧩
- Command-Line Interface: ⌨️ Easy to use with command-line arguments.
- Directory Selection: 📂 Allows users to specify the target directory for renaming.
To use the program, you need to compile the Go source code. Once compiled, you can run the executable with the following command-line arguments:
./renamer -dir <directory> [-prefix <prefix>] [-suffix <suffix>]- -dir : 📂 Specifies the directory containing the files to be renamed. This argument is required.
⚠️ - -prefix : ➕ Specifies the prefix to be added to the filenames. This argument is optional. ➡️
- -suffix : ➡️ Specifies the suffix to be added to the filenames. This argument is optional. ➕
Here are some examples of how to use the renamer command-line tool:
-
Adding a prefix to all files in a directory:
./renamer -dir /path/to/my/files -prefix "new_"This command will rename all files in the
/path/to/my/filesdirectory by adding the prefix "new_" to the beginning of each filename. For example,file.txtwould becomenew_file.txt. -
Adding a suffix to all files in a directory:
./renamer -dir /path/to/my/files -suffix "_renamed"This command will rename all files in the
/path/to/my/filesdirectory by adding the suffix "_renamed" to the end of each filename, before the file extension. For example,image.jpgwould becomeimage_renamed.jpg. -
Adding both a prefix and a suffix:
./renamer -dir /path/to/my/files -prefix "processed_" -suffix "_done"
This command will rename all files in the
/path/to/my/filesdirectory by adding the prefix "processed_" to the beginning and the suffix "_done" to the end of each filename, before the file extension. For example,document.pdfwould becomeprocessed_document_done.pdf. -
Using renamer on a directory with spaces in the name:
./renamer -dir "/path/to/my files" -prefix "new_"
If your directory contains spaces, enclose the directory path in quotation marks.
-
Using renamer on a directory with special characters in the name:
./renamer -dir "/path/to/my$files" -prefix "new_"
If your directory contains special characters, enclose the directory path in quotation marks.
-
Using renamer on a directory in the current working directory:
./renamer -dir ./myfiles -prefix "new_"If your directory is in the current working directory, use
./before the directory name.
-
Install Go: ⬇️ Ensure you have Go installed on your system. You can download it from golang.org. Follow the installation instructions for your operating system.
-
Clone the Repository: 📥 Clone this repository to your local machine using Git. If you don't have Git installed, you can download it from git-scm.com.
git clone <repository_url>
Replace
<repository_url>with the actual URL of your Git repository. -
Navigate to the Project Directory: 🚶 Use the
cdcommand to navigate to the project directory that you just cloned.cd renamer -
Build the Executable: 🔨 Run the following command to build the executable:
go build -o renamer
This will create an executable file named
renamer(orrenamer.exeon Windows) in the current directory. 🏁 The-o renamerpart is crucial for correctly naming your executable.-
For Linux/macOS: You might need to make the executable file executable:
chmod +x renamer
-
For Windows: The
renamer.exefile will be directly executable.
-
-
Optional: Move the executable to a directory in your PATH To make the
renamerexecutable available from anywhere in your system, you can move it to a directory that is in your system's PATH environment variable.- Linux/macOS:
sudo mv renamer /usr/local/bin/
- Windows:
Add the directory containing
renamer.exeto your system's PATH environment variable through the system settings.
- Linux/macOS:
This project uses the standard Go library and does not require any external dependencies. 🎉 This keeps the tool lightweight and easy to use.
Contributions are welcome! 🥳 If you find a bug 🐛, have suggestions for improvements 💡, or want to add new features 🚀, please feel free to contribute. Here's how:
-
Fork the repository: Click the "Fork" button on the top right of the repository page.
-
Clone your fork: Clone the forked repository to your local machine.
git clone [https://github.com/your-username/renamer.git](https://www.google.com/search?q=https://github.com/your-username/renamer.git) -
Create a new branch: Create a branch for your changes.
git checkout -b feature/your-feature-name
-
Make your changes: Implement your changes or fixes.
-
Commit your changes: Commit your changes with a descriptive message.
git commit -m "Add your feature or fix" -
Push your changes: Push the changes to your forked repository.
git push origin feature/your-feature-name
-
Create a pull request: Go to the original repository on GitHub and create a pull request from your branch.
Please ensure your code adheres to the project's coding style and includes appropriate tests.
This project is licensed under the MIT License. ⚖️