开发者

batch/CMD move does not work with folders

开发者 https://www.devze.com 2022-12-15 10:15 出处:网络
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

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


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.


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...


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


Check if any of your files are opened by the system process. You should close all the files before attempting the move command

0

精彩评论

暂无评论...
验证码 换一张
取 消