Python is versatile programming language which is easy to learn for beginners. It’s usedIt’s working on on large scale projects as well as Small projects. Sometimes you want to rename or Add prefix to file name. However you can rename it easily by Right clicking on the file and Clicking on Rename. Let’s make twist, you want to add prefix to 100 files stored in specific folder. You are thinking about how long it will take to rename all the files.

Read More:
How To Install Python in Windows

This article will explain how to rename or add prefix into file name. We will use Python script to rename all the files stored in specific folder. It will also check for specific file extension.

How To Rename or Add Prefix Into the File Name Using Python Script

Python community serves thousands of libraries which helps in development. Python is dynamically typed and flexible, with code that is less verbose

Import Libraries

Import libraries using below statements. argparse to get user input from command line, os to get list and rename all the files.

Get Command line arguments

get_parser() will get arguments from user and set them in variable.

Rename Files

Getting all the files from specific folder location and extension. After getting files rename() will add prefix to fine name.

main() Function To Call All The Actions

Getting array of command line argument and calling the functions to rename all files.

Full Code

Now open Command Prompt or Terminal and Run below command.

.jpg: file extension

myPrefix_: New prefix you want to add in file name.

Python Batch File Add Prefix Rename


Read More:

Create Twitter Bot Using Python and Tweepy

sSwitch – JQuery Plugin For Sliding Toggle Switches

How To Create Simple JQuery plugin

How To Implement Infinite Scroll Using JQuery, Ajax and PHP

Integrate Google Prettify in Html Page

Verify Your Server Meets PayPal Payment Gateway Requirements

Integrate google reCAPTCHA in your website

Create Webservice using Slim Framework

Create Twitter Bot Using Python and Tweepy

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">