"Access denied" when renaming folder from command line

Hi all.

I'm dealing with a strange problem.
I have to order and clean a quite complex folder structure, and I'm managing that with some batches to rename the folders from command line.

The main structure is something like that:


Sometimes, there are subfolders into the "UNIT" folders, such as:


My need is to rename the "UNIT" part of these folders. I do not have any problems when I rename a folder which do not have subfolders, but otherwise I get an "Access denied" error each time I try to rename a folder containing subfolders.

For example:
Let's take 2 folders:


rename E:\MAIN\NAMES_10\WORKUNIT    UNIT_1             >>>>     OK
rename E:\MAIN\NAMES_24\RESTUNIT    UNIT_2             >>>>     ACCESS DENIED

I first thought that some file in the "LOCATION" folders was preventing the system from renaming it, so I also tried to empty some of them (including from system and hidden files): the rename command still fails with "access denied"
No processes are working on these folders.

And the most strange fact: if I move or copy these folders to another location (say C:\users\spacexion\desktop\NAMES_10\RESTUNIT\CHICAGO) I can rename RESTUNIT to UNIT_2 from command line with no troubles!

I suspected some inherited rights issue, but I compared them on many folders and all seems correct with NT rights. Thus, if it was an issue right, I suppose that I couldn't rename the "UNIT" level folder too.
Furthermore, I also can rename these "locked" folders from Windows Explorer, so I really don't understand what's going on....

Any idea?

5 answers Last reply Best Answer
More about access denied renaming folder command line
  1. If you can rename in explorer then it is not a permissions issue.

    I would move the file directorys, rename, move it back.
  2. Ohh, did you open command prompt as administrator?
  3. Thanks for the reply.

    Yes, I also opened cmd as admin.

    I already considered the "move, rename, move back" solution, but I would rather prefer to avoid it: 75 000 files, 5 500 directories, and near to 2TB of data. If something should go wrong in the process, I would end up with a total mess....
  4. Try renaming the file via safemode
  5. Best answer
    Then it sounds like this data is critical enough that it should be being backed up in the first place
Ask a new question

Read More

Command Line