ChatGPT and File Renaming
1 minute read •
Backstory
While writing and the previous post I ran into an “issue” that post file names had spaces in them and special characters like :
, I could rename them manually but why not use script to do this automatically?
The Programming Asking
After a quick web search I understood that this will be hard to do (a lot of sed
and bash tricks, sounds like data loss), so I asked ChatGPT to write the script. After countless tweak requests and git restore ./
we have finally got it, script that works for English and Russian, it makes everything lowercase, replaces spaces with dashes and removes spacial characters like said :
, I don’t know how it works but here is it:
#!/usr/bin/env bash
# Made by ChatGPT and countless tweak requests
# Script for renaming files to be web-friendly (kebab-case without special characters)
# Function to rename files
# Check if a directory argument is provided, otherwise use the current directory
if [; then
target_directory=""
else
target_directory="."
fi
# Call the function with the specified directory
The script can take directory name as an argument (e.g posts
) and rename everything in it, that’s all it does :)
Anyway, I have wrote this to let you know why the script may break your files and appreciate how useful GPT can be sometimes.