> For the complete documentation index, see [llms.txt](https://learnimportant.gitbook.io/learn-important/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnimportant.gitbook.io/learn-important/windows10/rename-directory-from-command-line.md).

# Rename directory from command line

## Rename directory from command line

by SRINI

In [Renaming files from command line](https://www.windows-commandline.com/rename-file-from-command-line/) we saw how to rename files using ***Rename*** command.   We can use ***Rename*** command to rename directories too. See the syntax below.

```
Rename  dir_oldname  dir_newname
```

Example:

```
G:\data>mkdir dir1
G:\data>dir /b
dir1
G:\data>rename dir1 dir2
G:\data>dir /b
dir2
G:\data>
```

Note that, with rename command, we can’t move the files to another drive or directory. This command just renames the existing file/folder and does not create a new file.  That is why it does not accept full path for the target file name. If you try to do that you will get the error – “*The syntax of the command is incorrect.*”

Example:

```
C:\docs>ren 1.txt c:\docs\2.txt
The syntax of the command is incorrect.
```

The below rename command works fine.

```
C:\docs>ren c:\docs\1.txt 2.txt
C:\docs>dir /b
2.txt
```

We can also use *ren* (the short form of rename) for rename operations.  Both *Ren* and *Rename* refer to the same command.

This command can be used to rename files or directories on all Windows OS editions i.e Windows 2000, XP, Vista and Windows 7.

*Related Posts:*

[Delete directory from Windows command line](https://www.windows-commandline.com/delete-directory-from-command-line/)16 comments… [add one](https://www.windows-commandline.com/rename-directory-from-command-line/#commentform)

* Thai

  Can we use wildcats when renaming directories[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=100#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-100)
* Sumeeth Tewar

  rename \*.txt \*.doc\
  will definetely work :)\
  it does accept wild cards.[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=106#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-106)
* Techblogger

  Thanks for correcting me Sumith. Removed my earlier comment.[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=107#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-107)
* Anonymous

  how do you deal with spaces in the directory you need to rename?[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=142#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-142)
* Techblogger

  Specify the directory name in quotes. See below examples

  ren "directory with spaces" newdir

  ren "directory with spaces" "another directory with spaces"[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=143#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-143)
* Anonymous

  In Win 7 you cannot rename directories! It just returns “Access denied”[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=2081#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-2081)
* Anonymous

  Please ignore my previous comment. rename works fine.[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=2082#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-2082)
* Guillaume Drolet

  What causes Access denied exactly? I somehow got it to work. I used rename then I tried again move and move was working after that. I have no idea what I was doing wrong because I tried everything I did at first with move and it didn’t give me access denied again.

  Of course I did start the command prompt with administrator rights (well at first I didn’t but I restarted it with admin rights and it was still giving me the same error)[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=6404#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-6404)
* Prasad Shetty

  thanks[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=12218#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-12218)
* Nathan

  Thanks this helped a lot, we have a network and I “think” the back up here sometimes locks files even though nobody has them open.

  @Guillaume Drolet I got “Access denied” when the folder was highlighted in Explorer.\
  Not sure if that’s what caused it.[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=24872#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-24872)
* Owen

  Wildcards in W7 do NOT work.

  For example:\
  ren \*.RDX \*.REP from within the relevant folder (not root) gets ‘syntax error’.

  Also tried:\
  ren ??????.RDX ??????.REP with same result….[REPLY](https://www.windows-commandline.com/rename-directory-from-command-line/?replytocom=24995#commentform) [LINK](https://www.windows-commandline.com/rename-directory-from-command-line/#comment-24995)
* Doug

  You must use cmd in administrator mode. Right click on cmd and select run as administrator
