≡ Menu

Rename file from command line

We can use the built-in command line utility rename to change the name or extension of a file. Note that this command is just to rename a file keeping it in the same folder and can’t be used to move to another folder. See below rename command’s syntax explained with examples.

Syntax of rename command:

rename  file_path  new_name


rename  d:\data\file1.doc file2.doc

After executing the above command we’ll have file2.doc in the folder d:\data

Change file extensions in bulk using rename command

We can change the extension of a set of files in one step using rename command. For example, you have set of files with extension .html and you want to rename them to .txt.  You can do this with the below command

rename  *.html   *.txt

Rename command works in all Windows versions – XP, Vista and Windows 7.


  1. If the files is being used by a program, then rename command fails with below error.
    C:\>rename data.xlsx newdata.xlsx
    The process cannot access the file because it is being used by
    another process.
  2. You also need to have sufficient privileges to rename the file.
    c:\>rename c:\windows\csc test
    Access is denied.
  3. Rename changes just the file name, it does not convert a file from one type to another. For example, if you rename a file from mp4 to mp3 extension, it does not change the file format. Renaming a doc file 'mydocument.docx' to 'mydocument.pdf' does not make the file readable in Acrobat Reader.
7 comments… add one
  • Aaron Brinkley

    Does the command have to be executed in the root directory, or can it be done in a subdirectory that is in the root directory? Also, can a directory be renamed (EXAMPLE: renaming Dell.dir to Newname.dir)?

  • ritz

    this command gives repeating of filename when there are more then 40 files in the folders ?
    any solution for renaming 100s of file ???

  • harsha

    i have
    4299999940_M_harsha.png these type of files in several sub folders, with similar name structure(42 as first part of name, 40_M_harsha as last part of name.. in between 6digits(which may contain 42 and 40 also.in this example it has 999999))
    i have to rename it as 99999..i.e, remove first and last part of file name which is common for all files in the subfolder
    another examples:
    4292345640_M_harsha.png -> 923456
    4291424040_M_harsha.png -> 914240
    could u please help

  • cameron

    how do I rename a file by keeping the last 20 characters. I have random file names however the last 20 characters are what I want to keep. They are dates and a document ID.

  • rivera cook

    filename too long cannot rename Please now setup new rename

  • jonathan

    I use, Batch Rename Files Tool. You can easily found hier BatchRenameFiles.org that allows you to quickly rename all the files in a specified directory.

Leave a Comment