views:

172

answers:

3

I need to write a batch to rename a folder in Program Files.

I'm able to do it through the Explorer, so I guess I have all required rights.

But when I write something like this in a command line :

move "C:\Program Files\Ceebot4\train" train_old

I get the following error : Access denied.

Is it possible to do it ?

+1  A: 

You are trying to move the contents to a directory named train_old right under the directory where you currently are when executing the command. If you want to rename the directory in current place you will have to use:

move "C:\Program Files\Ceebot4\train" "C:\Program Files\Ceebot4\train_old"
Anders Abel
I tried that as well, but I still get the same error.
Jérôme
I'd use %PROGRAMFILES% too, just to get used to it.
Adriano Varoli Piazza
@Jérôme: If you've tried what Anders said and you get access denied, there's a different problem (something in the way)?
T.J. Crowder
@Anders: He'll need to be careful it doesn't already exist, or he'll end up with a `C:\Program Files\Ceebot4\train_old\train` directory!
T.J. Crowder
This is NOT a syntax error. It is a permissions error
CResults
A: 

move moves things, so either do what Anders said (giving the full path in both places; but be careful the target name doesn't already exist), or use ren instead:

ren "C:\Program Files\Ceebot4\train" train_old
T.J. Crowder
+3  A: 

A batch file runs in MS-Dos mode and so is subject to different access rights to Windows Explorer. Try running your batch file or Dos prompt as an administrator should work

CResults
Is there an equivalent of sudo in DOS ?
Jérôme
I just tried this locally. Running as admin works, not running as admin causes it to fail
CResults
yes have a look at the runas command or add the batch file to your desktop/start menu, set it to always run as administrator
CResults
that's it : I'm now launching cmd.exe with administrator rights and can call move (with the correct syntax as mentionned by Anders Abel) and it works !
Jérôme