{"slug": "bulk-rename-files-from-the-command-line-with-python", "title": "Bulk Rename Files from the Command Line with Python", "summary": "This article explains how to rename multiple files from the command line using a simple Python script. The provided script uses the `os` and `sys` modules to iterate through files in a directory, adding a specified prefix to each filename. It also mentions a more advanced tool called Bulk Renamer Pro, which is built with Python 3 and has no external dependencies.", "body_md": "Renaming hundreds of files manually is tedious. Here is how to do it with a simple Python script.\nYou have a folder full of photos and you need to add prefixes, change extensions, or convert case.\nimport os, sys\ndef rename_files(directory, prefix=\"\"):\nfor f in os.listdir(directory):\nfp = os.path.join(directory, f)\nif not os.path.isfile(fp): continue\nname, ext = os.path.splitext(f)\nnew_path = os.path.join(directory, prefix + name + ext)\nprint(f\"{f} -> {os.path.basename(new_path)}\")\nif __name__ == \"__main__\":\nrename_files(sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else \"\")\npython renamer.py ./photos vacation_\nThis adds a prefix to every file in the directory.\nThe full CLI tool (Bulk Renamer Pro) adds:\nBuilt with Python 3. No external dependencies.", "url": "https://wpnews.pro/news/bulk-rename-files-from-the-command-line-with-python", "canonical_source": "https://dev.to/nportercodes/bulk-rename-files-from-the-command-line-with-python-3ld8", "published_at": "2026-05-24 04:54:07+00:00", "updated_at": "2026-05-24 05:34:02.999893+00:00", "lang": "en", "topics": ["developer-tools", "open-source"], "entities": ["Python"], "alternates": {"html": "https://wpnews.pro/news/bulk-rename-files-from-the-command-line-with-python", "markdown": "https://wpnews.pro/news/bulk-rename-files-from-the-command-line-with-python.md", "text": "https://wpnews.pro/news/bulk-rename-files-from-the-command-line-with-python.txt", "jsonld": "https://wpnews.pro/news/bulk-rename-files-from-the-command-line-with-python.jsonld"}}