Windows – Rename files in a batch file

batchrenamewindows 7

I want to rename file1 to file2 using a batch file in Windows 7 but with no luck.

Below is the batch file:

@echo off
c:
cd\test
ren file1 file2

Error message I get is

syntax error.

Update to my question:
However, to be more specific, the following is the content of my script named update.cmd which I will run as administrator in Windows 7.

Here it is:

:START
cls
cd C:\Program Files\Autodesk\Revit Structure 2012\Program
ren C:RevitMFC.dll RevitMFC_dll.bak

When I cross check the program lines above using cmd.exe run as administrator, I found out the error msg is "access is denied".

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Ben>cd c:\program files\autodesk\revit structure 2012\program

c:\Program Files\Autodesk\Revit Structure 2012\Program>ren c:revitmfc.dll revitm fc_dll.bak Access is denied.

c:\Program Files\Autodesk\Revit Structure 2012\Program>

My question: How do I overcome this "Access is denied" ?

Best Answer

If

ren file1 file2

gives a syntax error, there are most certainly spaces in the files' names.

Try this instead:

ren "file1" "file2"
Related Question