Categories: Windows Commands

Rename file from command line [CMD]

We can use the command rename to rename files from windows command prompt(CMD). Find below syntax of the command with examples.

Syntax of rename command:

rename  file_path  new_name

Example:

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

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

Ren is alias for rename, so both refer to the same command.

Errors:

  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.
    C:\>
  2. You also need to have sufficient privileges to rename the file.
    c:\>rename c:\windows\csc test
    Access is denied.
    c:\>
  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.

More Reading

Rename file extensions in batch from command prompt

Srini

View Comments

  • 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)?

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

  • 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

  • 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.

  • 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.

  • Simple stuff. Been there and done that but I have a mess of files that contain a "%20" or several in the filename. I need help to sort this out. My REXX program has produced a batch file containing lines like these:

    ren "CORN%2~1.JPG" corn_escaLator.jpg
    ren "CHOCO%~1.JPG" choco_Lady.jpg
    ren "CAT%20~4.JPG" cat_wet_getting_bathed.jpg
    ren "CAT%20~3.JPG" cat_burrito.jpg
    ren "CAT%20~2.JPG" cat_bra.jpg
    ren "CAT%20~1.JPG" cat_bite_nose.jpg
    ren "BOOTY%~1.JPG" booty_cake.jpg
    ren "BIRD%2~2.JPG" bird_watersLide.jpg
    ren "BIRD%2~1.JPG" bird_mouth_dog.jpg
    ren "BIG%20~1.JPG" big_mac.jpg
    ren "BANK%2~1.JPG" bank_cake.jpg
    ren "ANGEL%~1.JPG" angeL_of_war.jpg

    Suffice to say it isn't working as intended. I get tons of
    "The system cannot find the file specified." messages.

    I prefer not to use the powershell whether I have it or not in case I need to run this in a more primitive Windows. I have tried rename instead of ren and without double quotes. I have administrator privileges.

    I am running Windows7 32-bit.

  • I use windows 10, and I did the steps, even in the location but it 'couldn't find the file specified.' Please help.

  • I have a lot of files with the same date stamp in which I wish to eliminate.
    Can I use * to find and replace this using the replace command?

    An example is 172794 (2021_10_09 09_36_16 UTC).xls

    • Yes, * would work for this case. If you need to delete such files in the current directory

      del "*2021_10_09 09_36_16 UTC.xls"

Recent Posts

Add new user account from command line (CMD)

Adding users from command line is much easier than going through the UI. It saves…

4 years ago

Delete directory from command line [Rmdir]

Do you want to delete a directory from Windows command prompt(CMD)? This post explains how…

4 years ago

TaskKill: Kill process from command line (CMD)

We can kill a process from GUI using Task manager. If you want to do…

4 years ago

Kill Chrome from command line

Chrome is definitely the stable browser compared to other ones and it has been my…

4 years ago

Find windows OS version from command line

Windows has multiple command line utilities that can help find the version of the Windows…

4 years ago

How to check if Windows 32 or 64 bit?

There are multiple ways to check whether a Windows computer is running 32-bit OS or…

7 years ago