A simple Node.js utility to classify and rename files in a folder.
Table of Contents
This utility helps organize your cluttered dump/
folder by classifying files into type-based subdirectories and renaming them in a clean, indexed format.
Organized folders look like this:
dump/
├── _images_/
├── _videos_/
├── _audio_/
├── _documents_/
└── _others_/
- Node.js
Make sure you have Node.js installed.
node -v
- Clone the repo
git clone https://github.com/siddharthaasal/rename-by-type.git
cd rename-by-type
-
Open index.js and set the dumpFolderPath variable (near the top of the file) to the path of your target folder. This is the directory whose files you want to organize.
-
Run the script:
node index.js
-
Automatically classifies files into:
_images_
: jpg, jpeg, png, gif_videos_
: mp4, mkv, avi, mov_audio_
: mp3, wav, flac_documents_
: pdf, doc, docx, txt_others_
: anything else
-
Files are renamed to:
01_images.jpg
02_images.jpg
...
- Use
path.join()
for OS-independent compatibility - Add support for async file operations
- Prevent overwriting by checking if renamed file exists
- Sanitize filenames to remove special characters
- Add CLI interface (e.g.,
--dry-run
,--input
,--verbose
) - Log actions and errors to a log file
- Handle files without extensions
Distributed under the MIT License.
Siddharth Aasal - LinkedIn | Mail
Project Link: https://github.com/siddharthaasal/rename-by-type