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
    
@slhck, actually, that does work. Try it! –  Synetech Jun 7 '12 at 20:45
    
@BenBever, there is nothing wrong with the syntax you entered in the question, so you may have fixed it while typing the question. Check the actual .bat file to make sure there isn't a syntax error. –  Synetech Jun 7 '12 at 20:47
2  
@Synetech Well, learned something new then ;) –  slhck Jun 7 '12 at 20:47
    
Generally, you can do this sort of thing so long as the character right after the command name is a delimiter (e.g. cd\progra~1, dir/s/o/a/p, foobar/?), but not always (e.g., attrib+r+a+s+h a.txt won't work). –  Synetech Jun 7 '12 at 20:50
    
@Synetech: Since DOS 3.0, spaces after a command are optional if the following character is a /, \ or .. I still get command not found every once in a while for executing cd.. in bash... –  Dennis Jun 8 '12 at 1:04
show 6 more comments

3 Answers

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
    
If Dennis is correct (and probably is), then the actual error message is The syntax of the command is incorrect. –  Synetech Jun 7 '12 at 20:53
add comment

There should not be a \ after the CD command.

Try this:

@echo off
c:
cd test
ren file1 file2
share|improve this answer
    
You could even shorten it up by removing the c: & cd test and simply give the command on one line with the path like this: ren c:\test\file1 file2 –  CharlieRB Jun 7 '12 at 20:45
    
Why not? It works. Try it! –  Synetech Jun 7 '12 at 20:45
    
@Synetech You're right. In all my years I have never used it. So it looked odd to me. Thanks for pointing that out. I think Dennis is on the right thought path now. –  CharlieRB Jun 7 '12 at 20:49
    
yes, there's all these weird things we keep noticing. There were a couple I found out about in the past year or two. Check my comment to the main question for details about this. –  Synetech Jun 7 '12 at 20:53
    
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 ------------------------------------------------------------ I cross check the program lines using cmd.exe rus as administrator and I found out the error msg is access is denied. –  Ben Bever Jun 8 '12 at 9:29
add comment

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
    
The file or folder is not marked read only. I can change the file name using Explorer but not using the script I intend to use. –  Ben Bever Jun 8 '12 at 19:54
add comment

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.