4

I wrote a small script in a bat file that I use to create backups of a folder on my computer:

rmdir "Folder - Backup (Old)" /S /Q
move "Folder - Backup" "Folder - Backup (Old)"
mkdir "Folder - Backup"
xcopy /e /h "Folder"\*.* "Folder - Backup"

I recently moved "Folder" along with the backup script into a new directory and now the script isn't working:

move "Folder - Backup" "Folder - Backup (Old)"
The filename or extension is too long.
        0 dir(s) moved.

I'm guessing this is caused by the full file path of Folder being too long, but I don't have this problem when I rename the folder using Windows Explorer so it's not like this operation isn't possible in Windows. Is there a work-around for this problem?

Ajedi32
  • 45,670
  • 22
  • 127
  • 172

2 Answers2

4

Using move to do a rename is overkill. Try

ren "Folder - Backup" "Folder - Backup (Old)"
Neil
  • 54,642
  • 8
  • 60
  • 72
  • 1
    REN doesn't work on folders. you'll get a very vague 'The syntax of the command is incorrect' error – georgiecasey Sep 11 '14 at 04:43
  • 1
    @georgiecasey The cases where `ren` does not work are a) Can only have exactly two arguments b) Second argument can only be a file name, not a path or drive c) First argument cannot be a wildcard to rename a folder. – Neil Sep 14 '14 at 18:57
0

Use powershell's move-item instead of move.

This works especially well if you actually need to move something (vs doing a rename).

powershell move-item 'Folder - Backup' 'Folder - Backup (Old)'

Ryan
  • 164
  • 1
  • 9