Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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" ?

share|improve this question

3 Answers 3

If

ren file1 file2

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

Try this instead:

ren "file1" "file2"
share|improve this answer

There should not be a \ after the CD command.

Try this:

@echo off
c:
cd test
ren file1 file2
share|improve this answer

You are likely getting the "Access Denied" error because the file or folder is read only. The other possibility is the file is in use.

You can check the file attributes as follows. To check the folder's attributes leave out the file name.

attrib  [[Drive:][Path] FileName]

Here is more info on how to use the attrib command.

In order to rename the file with your batch file, you will need to modify the attributes of the file, and possibly the folder. After renaming the file change the attributes back.

Word of warning; changing the name of a dynamic link library (dll) file can cause the program(s) it is associated with to stop working.

share|improve this answer

protected by Community Mar 1 '13 at 17:59

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>                   with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.1.30.2262\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Super User works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </noscrip"], "copyright__copyright__copyright": ["hanging the name of a dynamic link library (dll) file can cause the program(s) it is associated with to stop working.\n\nshare|improve this answer\n\nprotected by Community Mar 1 '13 at 17:59\n\nThank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.\n\nWould you like to answer one of these unanswered questions instead?\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question.", "hanging the name of a dynamic link library (dll) file can cause the program(s) it is associated with to stop working.\n\nshare|improve this answer\n\nprotected by Community Mar 1 '13 at 17:59\n\nThank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.\n\nWould you like to answer one of these unanswered questions instead?\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question.", "hanging the name of a dynamic link library (dll) file can cause the program(s) it is associated with to stop working.\n\nshare|improve this answer\n\nprotected by Community Mar 1 '13 at 17:59\n\nThank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.\n\nWould you like to answer one of these unanswered questions instead?\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}