batch/CMD move does not work with folders

10,592

Solution 1

Try to have the admin take ownership with takeown /F <filename> (for files) and
takeown /f <foldername> /r /d y (for folders) and then try to move the file or folder

after taking ownership set admin file permission to full control with the cacls utility :

cacls <folder> /T  /G admin:F

Solution 2

I had this same issue so did a bit of experimenting.

It seems that as of Windows 7, ANY open handle to the directory in windows will cause an access denied. This includes explorer open in that directory, and people using that directory over the network.

You can use rename if you are renaming a directory but otherwise keeping the path the same. This will work EVEN if there is an open handle such as an explorer window open within that directory (the path within the window will get refreshed) Which is a good solution if you are just trying to backup information as a fail-safe, but not anything you are likely to use for automated network backing up etc.

if the permissions settings did not work, then it is almost certainly an open handle from explorer, an executable running from that directory or some thing similar.

Solution 3

In Windows 7 you have to run the batch as administrator. But then make sure to change dir to homedir at begginning of your script, coz current dir will be different than what it should be when you run as admin..

Alternatively you can start a cmd window with admin rights then you can type or drag&drop batch files into it...

another way to do is to xcopy with /R option, then delete source... Or simply use robocopy

robocopy %1 c:\specifiedfolder /E /IS /MOVE

but still you need to dele skipped files...

Share:
10,592
spoekes
Author by

spoekes

Updated on June 22, 2022

Comments

  • spoekes
    spoekes almost 2 years

    I have a simple .bat (move.bat) file in the SendTo folder which moves files and directories from any location to a specified folder by using the context menu. This worked on XP. In Windows 7 however i get an access denied error. It doesn't even work with cmd opened as admin (runas).

    content of move.bat:

    move %1 c:\specifiedfolder